WPF에서 마우스 오버시 이미지를 변경하기 위한 Image Source 변경.
1. 첫번째 방법(Code Behind)
var uriSource = new Uri(@"/WpfApplication1;component/changeimage.png", UriKind.Relative);
ImageName.Source = new BitmapImage(uriSource);
ImageName.Source = new BitmapImage(uriSource);
2. 두번째 방법(Code Behind)
string uriSource = "pack://application:,,,/AssemblyName;component/changeimage.png";
ImageName.Source = new ImageSourceConverter().ConvertFromString(uriSource) as ImageSource;
ImageName.Source = new ImageSourceConverter().ConvertFromString(uriSource) as ImageSource;
3. 세번째 방법(Code Behind)
Assembly asm = Assembly.GetExecutingAssembly();
Stream iconStream = asm.GetManifestResourceStream("changeimage.png");
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = iconStream;
bitmap.EndInit();
ImageName.Source = bitmap;
Stream iconStream = asm.GetManifestResourceStream("changeimage.png");
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = iconStream;
bitmap.EndInit();
ImageName.Source = bitmap;
4.xaml 코드에서의 변경
<Image x:Name="img">
<Image.Style>
<Style>
<Setter Property="Image.Source" Value="/WpfApplication1;component/original_image.png" />
<Style.Triggers>
<Trigger Property="Image.IsMouseOver" Value="True">
<Setter Property="Image.Source" Value="/WpfApplication1;component/change_image.png"/>
</Trigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
<Image.Style>
<Style>
<Setter Property="Image.Source" Value="/WpfApplication1;component/original_image.png" />
<Style.Triggers>
<Trigger Property="Image.IsMouseOver" Value="True">
<Setter Property="Image.Source" Value="/WpfApplication1;component/change_image.png"/>
</Trigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
'Development > C#' 카테고리의 다른 글
C# Using a mutex to prevent multiple application from running (0) | 2012.02.24 |
---|---|
윈도우 시작프로그램 등록 및 삭제 (0) | 2012.02.09 |
Icon in Add/Remove Programs for ClickOnce Application (0) | 2012.01.31 |
ClickOnce 정보 (0) | 2012.01.31 |
DataGrid 바인딩 (0) | 2011.09.27 |