I have the following code in XAML:
<data:DataGridTemplateColumn>
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image x:Name="picture" Width="200" Height="130" Visibility="Visible"/>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
How would do I this in the code behind (C#), without using this XAML code?
EDIT:
Here is the solution I am using:
Creating a Silverlight DataTemplate in code
This lets me do exactly what I want.
For example, you have a simple
DataGridIf you want to have several templates applied to a single DataGridRow, you can change visibility of internal parts inside the template:
There is the part with
Imageand the part withTextBoxthat 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.