Ich habe diese ResourceDictionary
in Main.xaml
:Wie Bildquelle in C# zu XAML statische Ressource programmgesteuert festgelegt?
<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>
Ich stellte zunächst das Bild mit:
<Image Name="TypeIcon" HorizontalAlignment="Left" VerticalAlignment="Center"
Source="{StaticResource Customer}" Height="16" Width="16"/>
Ich versuche TypeIcon
‚s Source
von Kunden-Projekt in ein zu ändern C# -Methode.
Ich habe versucht, mit:
TypeIcon.Source = "{StaticResource Project}";
Aber ich bekomme diese Fehlermeldung:
Cannot implicitly convert type
string
toSystem.Windows.Media.ImageSource
Ich habe versucht, Definieren Sie das Bild mit new ImageSource()
, aber das funktioniert auch nicht.
Wie kann ich das Bild Source
programmgesteuert in C# ändern?
Der' Media' Namespace ist nicht verfügbar setzen System.Windows.Media.ImageSourceConverter' –