Note that there are some explanatory texts on larger screens.

plurals
  1. POComboBox(WPF) template in dictionary
    text
    copied!<p>I'm practicing C# with wpf and I'm trying to use template formatting.<br> At this time, I have a customized combobox bind link this:</p> <pre><code>&lt;ComboBox Height="23" HorizontalAlignment="Left" Margin="177,28,0,0" Name="JoinedFiles_combobox" VerticalAlignment="Top" Width="164" Grid.Column="1" SelectionChanged="JoinedFiles_combobox_SelectionChanged"&gt; &lt;ComboBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Canvas Height="18"&gt; &lt;Image Name="ImageName" Height="16" Width="16" Canvas.Left="1" Canvas.Top="1"/&gt; &lt;TextBlock Text="{Binding Name}" Canvas.Left="26" Canvas.Top="1" Width="120"/&gt; &lt;/Canvas&gt; &lt;DataTemplate.Triggers&gt; &lt;DataTrigger Binding="{Binding PictureID}" Value="0"&gt; &lt;Setter TargetName="ImageName" Property="Source" Value="Resources\0.png"/&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Binding="{Binding PictureID}" Value="1"&gt; &lt;Setter TargetName="ImageName" Property="Source" Value="Resources\1.png"/&gt; &lt;/DataTrigger&gt; &lt;/DataTemplate.Triggers&gt; &lt;/DataTemplate&gt; &lt;/ComboBox.ItemTemplate&gt; &lt;/ComboBox&gt; </code></pre> <p>As I want another combobox like this in another xaml file (another window), I am trying to put this as a template in my <code>app.xaml</code> file. This will prevent the copying of code and simplify things. </p> <p>This is what I wrote in the <code>app.xaml</code> file:</p> <pre><code>&lt;Application.Resources&gt; &lt;ResourceDictionary&gt; &lt;ControlTemplate x:Key="CustomisedComboBox" TargetType="{x:Type ComboBox}"&gt; &lt;ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Canvas Height="18"&gt; &lt;Image Name="ImageName" Height="16" Width="16" Canvas.Left="1" Canvas.Top="1"/&gt; &lt;TextBlock Text="{Binding Name}" Canvas.Left="26" Canvas.Top="1" Width="120"/&gt; &lt;/Canvas&gt; &lt;DataTemplate.Triggers&gt; &lt;DataTrigger Binding="{Binding PictureID}" Value="0"&gt; &lt;Setter TargetName="ImageName" Property="Source" Value="Resources\0.png"/&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Binding="{Binding PictureID}" Value="1"&gt; &lt;Setter TargetName="ImageName" Property="Source" Value="Resources\1.png"/&gt; &lt;/DataTrigger&gt; &lt;/DataTemplate.Triggers&gt; &lt;/DataTemplate&gt; &lt;/ItemTemplate&gt; &lt;/ControlTemplate&gt; &lt;/ResourceDictionary&gt; &lt;/Application.Resources&gt; </code></pre> <p>The problem is that it can't find ItemTemplate in my control template. How can I give it that item template?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload