Reputation: 1
I'm struggling with this like about 2 Days and can't get an answer or solution to my problem. I'm using C# WPF and my prob is here:
I have a Datagrid which ItemsSource gets binded. Every TextColumn is displaying its value properly. The DataTemplateColumns which contains a picture or a button does not show its value as long i do not enter that Cell. I want to have my DataGrid Read-Only and get the pictures displayed at once and not by clicking in the cell. But they only shows if you click into the cell. I already tried different Image formats (png,bmp,jpg)
So whats the problem with that DataGrid?
Here is the XAML part with the DataTemplaceColumn:
<DataGrid AlternatingRowBackground="Gainsboro"
AlternationCount="2"
AutoGenerateColumns="False"
Height="200"
HorizontalAlignment="Left"
ItemsSource="{Binding}"
Name="DgMain"
VerticalAlignment="Top"
Width="778"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserResizeRows="False"
CanUserSortColumns="True"
IsReadOnly="True">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Pic">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<Image x:Name="ImgDgMainPic"></Image>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding pic}" Value="pic1">
<Setter TargetName="ImgDgMainPic" Property="Source" Value="Images\picture1.png"/>
</DataTrigger>
<DataTrigger Binding="{Binding pic}" Value="pic2">
<Setter TargetName="ImgDgMainPic" Property="Source" Value="Images\picture2.png"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
The Value which the DataTriger binds is string which contains "pic1" or "pic2" as you can see.
Thanks in Advance
Upvotes: 0
Views: 325
Reputation: 81243
Instead of using CellEditingTemplate
, you should use CellTemplate
-
<DataGridTemplateColumn.CellTemplate>
......
</DataGridTemplateColumn.CellTemplate>
CellEditingTemplate is shown once you double click on the cell to make it editable. whereas CellTemplate is what you are looking for.
Upvotes: 2