
我甚至不知道开始做这件事.
<GrID x:name="Stations_Template"> <GrID.RowDeFinitions> <RowDeFinition Height="auto" /> </GrID.RowDeFinitions> <GrID.ColumnDeFinitions> <ColumnDeFinition WIDth="*" /> <ColumnDeFinition WIDth="*" /> <ColumnDeFinition WIDth="*" /> <ColumnDeFinition WIDth="*" /> <ColumnDeFinition WIDth="*" /> </GrID.ColumnDeFinitions> <TextBlock GrID.Column="0" Text="First name: " /> <TextBlock GrID.Column="1" Text="{Binding Path=sname}" /> <TextBlock GrID.Column="2" Text="Last name: " /> <TextBlock GrID.Column="3" Text="{Binding Path=mahoz}" /> <CheckBox GrID.Column="4" Content="Is Active?" IsEnabled="False" IsChecked="{Binding Path=isactive}" /> </GrID> </DataTemplate> </ListBox.ItemTemplate> </ListBox>解决方法 使用矩形首先填充行,然后向其中添加数据. <GrID Background="White"> <GrID.RowDeFinitions> <RowDeFinition Height="auto"/> <RowDeFinition Height="auto"/> <RowDeFinition Height="auto"/> <RowDeFinition Height="auto"/> </GrID.RowDeFinitions> <Rectangle GrID.Row="0" Fill="AliceBlue" /> <TextBlock GrID.Row="0" Text="Row 1" HorizontalAlignment="Center"/> <Rectangle GrID.Row="1" Fill="AntiqueWhite" /> <TextBlock GrID.Row="1" Text="Row 2" HorizontalAlignment="Center"/> <Rectangle GrID.Row="2" Fill="AliceBlue" /> <TextBlock GrID.Row="2" Text="Row 3" HorizontalAlignment="Center"/> <Rectangle GrID.Row="3" Fill="AntiqueWhite" /> <TextBlock GrID.Row="3" Text="Row 4" HorizontalAlignment="Center"/> </GrID>
编辑:
如果您正在加载未知数量的项目,那么我认为您需要像itemscontrol这样的东西加载它们.然后您可以使用alternationcount和触发器来处理交替颜色.
<ItemsControl ItemsSource="{Binding DataList}" AlternationCount="2"> <ItemsControl.ItemTemplate> <DataTemplate> <GrID x:name="Foobar" margin="0,10"> </GrID> <DataTemplate.Triggers> <Trigger Property="ItemsControl.AlternationIndex" Value="0"> <Setter Property="Background" Value="Blue" Targetname="Foobar"/> </Trigger> <Trigger Property="ItemsControl.AlternationIndex" Value="1"> <Setter Property="Background" Value="Red" Targetname="Foobar"/> </Trigger> </DataTemplate.Triggers> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> 总结 以上是内存溢出为你收集整理的c# – 在WPF中更改网格行背景颜色全部内容,希望文章能够帮你解决c# – 在WPF中更改网格行背景颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)