WPF DataGrid ItemTemplate 问题
求助各位大神:代码如下,我的问题是我需要用datatemplate设置我datagrid中每行的显示样式,但是我用itemtemplate去引我定义好的datatempl...
求助各位大神:代码如下,我的问题是我需要用datatemplate设置我datagrid中每行的显示样式,但是我用itemtemplate去引我定义好的datatemplate,但是却引不上,没有任何的显示效果,请问是怎么回事?
我定义的DataTemplate:
<DataTemplate x:Key="MyTemplate" >
<Grid Name="bgcolor" Background="{x:Null}" Height="20">
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Path=A}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="50" Margin="5,0,0,0"/>
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=B}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="60" Margin="5,0,0,0"/>
<TextBlock Grid.Row="0" Grid.Column="2" Text="{Binding Path=C}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="60" Margin="5,0,0,0"/>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=C}">
<DataTrigger.Value>
<local:GlassStatus>MM</local:GlassStatus>
</DataTrigger.Value>
<Setter TargetName="bgcolor" Property="Background" Value="Red"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
datagrid部分:
<DataGrid ItemsSource="{Binding Path=Units}" Style="{x:Null}"
ItemTemplate="{StaticResource MyTemplate}"
Background="{x:Null}" ColumnHeaderStyle="{StaticResource UnitsColumnHeader}"
Width="auto" ColumnWidth="60" IsReadOnly="True"
CanUserResizeColumns="False" CanUserSortColumns="False"
Margin="40,0,0,0" >
</DataGrid>
同样的DataTemplate,我用ItemTemplate在ListBox中用就没有问题,分不多了,不好意思,求各位帮帮忙。 展开
我定义的DataTemplate:
<DataTemplate x:Key="MyTemplate" >
<Grid Name="bgcolor" Background="{x:Null}" Height="20">
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Path=A}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="50" Margin="5,0,0,0"/>
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=B}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="60" Margin="5,0,0,0"/>
<TextBlock Grid.Row="0" Grid.Column="2" Text="{Binding Path=C}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="60" Margin="5,0,0,0"/>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=C}">
<DataTrigger.Value>
<local:GlassStatus>MM</local:GlassStatus>
</DataTrigger.Value>
<Setter TargetName="bgcolor" Property="Background" Value="Red"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
datagrid部分:
<DataGrid ItemsSource="{Binding Path=Units}" Style="{x:Null}"
ItemTemplate="{StaticResource MyTemplate}"
Background="{x:Null}" ColumnHeaderStyle="{StaticResource UnitsColumnHeader}"
Width="auto" ColumnWidth="60" IsReadOnly="True"
CanUserResizeColumns="False" CanUserSortColumns="False"
Margin="40,0,0,0" >
</DataGrid>
同样的DataTemplate,我用ItemTemplate在ListBox中用就没有问题,分不多了,不好意思,求各位帮帮忙。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询