Ho un DataTemplate
definito in un file xaml a cui voglio accedere tramite codice C#. Qualcuno può dirmi come posso accedervi? Ho aggiunto un nuovo file ResourceDictionary
e il suo nome è Dictionary1.xaml. ho un modello di dati come ad esempio:Come posso accedere a ResourceDictionary in wpf dal codice C#?
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="mytemplate">
<TextBlock Text="Name:" Background="Blue"/>
</DataTemplate>
</ResourceDictionary>
non ho un ListBox
chiamato listBox1 e voglio assegnare alla sua Itemtemplate
proprietà ma io non sono sempre come posso farlo?
Non capisco. Questa risposta non usa la chiave. –
FindResource accetta un argomento, la chiave. typeof (yourDataTemplateTargetType) è la chiave in questo esempio. –
Ciao. Cosa succede se la chiave non è un tipo, ma una stringa come nell'esempio di OP? –