Windows Presentation Foundation
.NET Framework 的一部分,它提供统一的编程模型,用于在 Windows 上构建业务线桌面应用程序。
65 个问题
我对插入并绑定到 DataGridTemplateColumn 的 RichTextBox 感到疯狂。
我有
如您所见,在 DataGridTemplateColumn 的单元格中,我有四行,我希望这些行以不同的方式着色(esch 行为一种颜色)。
这是我生成列的方式:
<DataGridTemplateColumn Header="LOCATION" Width="*" CanUserSort="False" CanUserReorder="False" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<RichTextBox IsEnabled="False" BorderThickness="0" Background="Transparent">
<FlowDocument>
<Paragraph>
<Run Text="{Binding Location}"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
我该怎么办??
Note:此问题总结整理于:[C#7.0 - WPF] - RichTextBox in a DataGridTemplateColumn with binding
修复我的代码:
vm.People = new List<MyClass>(){ new MyClass (){
Location =new List<string> (){ "IP:","10","S/N:","6725542","Tag:","602","Mod:","Phaser"},
solidColorBrush =new List<SolidColorBrush> (){ new SolidColorBrush (Colors.Black),new SolidColorBrush (Colors.Red),new SolidColorBrush(Colors.Aqua),new SolidColorBrush (Colors.Aquamarine), new SolidColorBrush(Colors.Silver), new SolidColorBrush(Colors.Turquoise) } },
};
XAML中:
<StackPanel >
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Location[0]}" Foreground="{Binding solidColorBrush[0]}" FontWeight="Bold"/>
<TextBlock Text="{Binding Location[1]}" Foreground="{Binding solidColorBrush[1]}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Location[2]}" Foreground="{Binding solidColorBrush[2]}" FontWeight="Bold"/>
<TextBlock Text="{Binding Location[3]}" Foreground="{Binding solidColorBrush[3]}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Location[4]}" Foreground="{Binding solidColorBrush[4]}" FontWeight="Bold"/>
<TextBlock Text="{Binding Location[5]}" Foreground="{Binding solidColorBrush[5]}" />
</StackPanel>
</StackPanel>
如果答案是正确的,请点击“接受答案”并点赞。 如果您对此答案还有其他疑问,请点击“评论”。
注意:如果您想接收相关电子邮件,请按照我们的文档中的步骤启用电子邮件通知 此线程的通知。