私はMain.xaml
でこのResourceDictionary
を持っている:C#のイメージソースをXAML静的リソースにプログラムで設定する方法は?
<Window.Resources>
<ResourceDictionary>
<BitmapImage x:Key="Customer" UriSource="Icons/customer.png"/>
<BitmapImage x:Key="Project" UriSource="Icons/project.png"/>
<BitmapImage x:Key="Task" UriSource="Icons/task.png"/>
</ResourceDictionary>
</Window.Resources>
私が最初に使用して画像を設定します。
<Image Name="TypeIcon" HorizontalAlignment="Left" VerticalAlignment="Center"
Source="{StaticResource Customer}" Height="16" Width="16"/>
私はカスタマーにプロジェクトからTypeIcon
のSource
を変更しようとしていますC#メソッド。私が使用して試した
:
TypeIcon.Source = "{StaticResource Project}";
をしかし、私はこのエラーを取得する:
Cannot implicitly convert type
string
toSystem.Windows.Media.ImageSource
私はnew ImageSource()
を使用して画像を定義しようとしたが、これはどちらか動作しません。
C#で画像のSource
をプログラムで変更するにはどうすればよいですか?多くのグーグルでの後
'Media'名前空間には、'ユニバーサルアプリのため使用できませんSystem.Windows.Media.ImageSourceConverter' –