gpt4 book ai didi

.net - 在 DataGrid 单元格中添加一个小的彩色矩形

转载 作者:行者123 更新时间:2023-12-04 15:15:20 25 4
gpt4 key购买 nike

我希望在我的 DataGrid 中添加一个小 (10x10) 矩形作为单元格。我已经在对象中设置了它,我只是在寻找一种方法将它从代码中获取到我的 DataGrid 中。

这是我的 DataGrid XAML:

<DataGrid Name="dataGrid1" Grid.Row="2" AutoGenerateColumns="False" DataContext="{Binding}" HeadersVisibility="Column" 
HorizontalGridLinesBrush="#ccc" VerticalGridLinesBrush="#ccc" VirtualizingStackPanel.VirtualizationMode="Standard" Background="#FFF6F6F6" CanUserAddRows="False">
<DataGrid.Resources>
<ResourceDictionary Source="Pages/DataGridStyle.xaml" />
</DataGrid.Resources>
<DataGrid.Columns>
<!-- In here I would like a datagrid cell that is just a 10x10 box which uses {Binding Path=TemplateCellColour} (templatecellcolour is stored as a brush, is this an issue? -->
<DataGridTextColumn ElementStyle="{StaticResource CenterTextCell}" Width="0.5*" Binding="{Binding Path=TemplateCellID}" Header="ID"></DataGridTextColumn>
<DataGridTextColumn ElementStyle="{StaticResource CenterTextCell}" Width="1*" Binding="{Binding Path=CellWidth}" Header="Width"></DataGridTextColumn>
<DataGridTextColumn ElementStyle="{StaticResource CenterTextCell}" Width="1*" Binding="{Binding Path=CellHeight}" Header="Height"></DataGridTextColumn>
<DataGridTextColumn ElementStyle="{StaticResource CenterTextCell}" Width="1*" Binding="{Binding Path=CellTop}" Header="Top"></DataGridTextColumn>
<DataGridTextColumn ElementStyle="{StaticResource CenterTextCell}" Width="1*" Binding="{Binding Path=CellLeft}" Header="Left"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>

请查看评论以便更容易地理解我想要什么。

最佳答案

替换 DataGridTextColumnDataGridTemplateColumn .像这样的东西:

<DataGridTemplateColumn >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Rectangle Width="10" Height="10" Fill="{Binding TemplateCellColour}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

是的, TemplateCellColour应该是 Brush , 那是正确的。

关于.net - 在 DataGrid 单元格中添加一个小的彩色矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5474828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com