PDA

View Full Version : تغییر سورس imag در runtime



habib_namvar
یک شنبه 20 شهریور 1390, 11:13 صبح
سلام دوستان من اولین باریه که با wpf کار میکنم:افسرده:
میشه بگین چطور تصویر یک imag رو در حالت run time تغیر بدم مثلا با یه تایمر هر یه ثانیه یه تصویر

مهدی فرزاد
یک شنبه 20 شهریور 1390, 12:42 عصر
سلام
نیازی به تایمر نیست میتونید از Storyboard استفاده کنید <Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication5.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<Storyboard x:Key="Storyboard1" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="image">
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.9" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:5.7" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:6" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="image_Copy">
<EasingDoubleKeyFrame KeyTime="0:0:0.7" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.6" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.9" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="image_Copy1">
<EasingDoubleKeyFrame KeyTime="0:0:1.7" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:2.6" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:2.9" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="image_Copy2">
<EasingDoubleKeyFrame KeyTime="0:0:2.7" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:3" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:3.6" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:3.9" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="image_Copy3">
<EasingDoubleKeyFrame KeyTime="0:0:3.7" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:4" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:4.6" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:4.9" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="image_Copy4">
<EasingDoubleKeyFrame KeyTime="0:0:4.7" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:5" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:5.6" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:5.9" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
</EventTrigger>
</Window.Triggers>

<Grid x:Name="LayoutRoot">
<Image x:Name="image" Margin="80,67,99,71" Source="Image/DeleteRed.png"/>
<Image x:Name="image_Copy" Margin="80,67,99,71" Source="Image/Error.png" Opacity="0"/>
<Image x:Name="image_Copy1" Margin="80,67,99,71" Source="Image/new.png" Opacity="0"/>
<Image x:Name="image_Copy2" Margin="80,67,99,71" Source="Image/Report.png" Opacity="0"/>
<Image x:Name="image_Copy3" Margin="80,67,99,71" Source="Image/Setting.png" Opacity="0"/>
<Image x:Name="image_Copy4" Margin="80,67,99,71" Source="Image/Warning.png" Opacity="0"/>
</Grid>
</Window>

habib_namvar
یک شنبه 20 شهریور 1390, 12:52 عصر
ممنون که پاسخ دادید
من عکسام توی هر دفه لود شدن با قبل متفاوته
میشه بگید چطور باید از این شی استفاده کنم

habib_namvar
یک شنبه 20 شهریور 1390, 15:38 عصر
دوستان کسی نمیدونه باید چیکار کنم
فک کنید مثلا روی باتن کلیک کنم و سورس امیج عوض شه

idxxbi
یک شنبه 20 شهریور 1390, 18:41 عصر
:چشمک:


this.Background = new ImageBrush(new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "\\Image\\1.png")));

img1.Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "\\Image\\img1.png"));