Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to load different templates depending upon user input to a the list box
    text
    copied!<p>I'm trying to load a template for displaying a list box.Here i have two different templates </p> <p>and i have to load one template depending upon the configuration value.First give some idea </p> <p>that how to load different templates for a single list box.</p> <p>Here is my XAML code </p> <pre><code>&lt;Window x:Class="DynamicTemplate.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:local="clr-namespace:DynamicTemplate" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"&gt; &lt;Window.Resources&gt; &lt;ResourceDictionary&gt; &lt;DataTemplate x:Key="LargeTemplate"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBlock Text="Large Template" FontSize="10" Foreground="Black"/&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="SmallTemplate"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBlock Text="Small template" FontSize="10" Foreground="Blue"/&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ResourceDictionary&gt; &lt;/Window.Resources&gt; &lt;ListBox x:Name="MyListBox" Width="200" Height="200" ItemsSource="{Binding Path=list1}" &gt; &lt;ListBox.Style&gt; &lt;Style TargetType="ListBox"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding Path=size}" Value="Small"&gt; &lt;Setter Property="ListBox.ItemTemplate" Value="{StaticResource SmallTemplate}"/&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Binding="{Binding Path=size}" Value="Large"&gt; &lt;Setter Property="ListBox.ItemTemplate" Value="{StaticResource LargeTemplate}"/&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/ListBox.Style&gt; &lt;/ListBox&gt; &lt;/Window&gt; </code></pre> <p>Please try to help me i need to do this now. please check the code and reply me soon. Thanks in advance. </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