Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For example, you have a simple <code>DataGrid</code></p> <pre><code> &lt;sdk:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Items}"&gt; &lt;sdk:DataGrid.Columns&gt; &lt;sdk:DataGridTemplateColumn CellTemplate="{StaticResource ImageCellTemplate}"/&gt; &lt;/sdk:DataGrid.Columns&gt; &lt;/sdk:DataGrid&gt; </code></pre> <p>If you want to have several templates applied to a single DataGridRow, you can change visibility of internal parts inside the template:</p> <pre><code> &lt;DataTemplate x:Key="ImageCellTemplate"&gt; &lt;Grid&gt; &lt;StackPanel Orientation="Horizontal" Visibility="{Binding IsImageTemplate}"&gt; &lt;Image Width="20" Height="20"/&gt; &lt;TextBlock Text="{Binding Title}"/&gt; &lt;/StackPanel&gt; &lt;StackPanel Orientation="Horizontal" Visibility="{Binding IsTextBoxTemplate}"&gt; &lt;TextBlock Text="{Binding Id}" Foreground="Red"/&gt; &lt;TextBox Text="{Binding Title}"/&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; </code></pre> <p>There is the part with <code>Image</code> and the part with <code>TextBox</code> that are bound to the properties of an item view model (IsImageTemplate and IsTextBoxTemplate respectively). They are mutually exclusive and panels will not cover each other.</p> <pre><code>public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); var items = new List&lt;ItemViewModel&gt;() { new ItemViewModel{Id = 1, Title="First", IsImage = true}, new ItemViewModel{Id = 2, Title="Second", IsImage = false}, new ItemViewModel{Id = 3, Title="Third", IsImage = false} }; this.DataContext = new MainViewModel { Items = items }; } } public class MainViewModel { public List&lt;ItemViewModel&gt; Items { get; set; } } public class ItemViewModel { public int Id { get; set; } public string Title { get; set; } public bool IsImage { get; set; } public Visibility IsImageTemplate { get { return (IsImage == true) ? Visibility.Visible : Visibility.Collapsed; } } public Visibility IsTextBoxTemplate { get { return IsImage == false ? Visibility.Visible : Visibility.Collapsed; } } } </code></pre>
 

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