如何更改运行时gridview中存在的Ellipse颜色?(How to change the Ellipse color which is present in the gridview in ru

编程入门 行业动态 更新时间:2024-10-28 06:32:27
如何更改运行时gridview中存在的Ellipse颜色?(How to change the Ellipse color which is present in the gridview in runtime?) <DataGrid AutoGenerateColumns="False" Height="330" HorizontalAlignment="Left" Margin="5,70,0,0" Name="grdDeviceInfo" VerticalAlignment="Top" CanUserAddRows="False" IsReadOnly="True" Width="368" HorizontalScrollBarVisibility="Auto"> <DataGrid.Columns> <DataGridTextColumn Header="Channels" Width="100" Binding="{Binding ChannelNo}"></DataGridTextColumn> <DataGridTextColumn Header="Label" Width="200" Binding="{Binding Label}"></DataGridTextColumn> <DataGridTemplateColumn Header="Status" Width="60"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Ellipse Height="13" Name="grdfEllipse" Stroke="Black" Fill="{}" Width="20"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid>

代码背后:

List<IOInformation> lstIOStatus = new List<IOInformation>(); for (int i = 0; i < channelStatus.Count(); i++) { // var columns = line.Split('\t'); lstIOStatus.Add(new IOInformation { ChannelNo = "Channel " + j++, Label = labeldata[i], MasterStatus = Convert.ToBoolean(channelStatus[i]) }); } this.grdDeviceInfo.ItemsSource = lstIOStatus;

我想将椭圆颜色更改为绿色(如果为真),或者红色(如果为假)。

<DataGrid AutoGenerateColumns="False" Height="330" HorizontalAlignment="Left" Margin="5,70,0,0" Name="grdDeviceInfo" VerticalAlignment="Top" CanUserAddRows="False" IsReadOnly="True" Width="368" HorizontalScrollBarVisibility="Auto"> <DataGrid.Columns> <DataGridTextColumn Header="Channels" Width="100" Binding="{Binding ChannelNo}"></DataGridTextColumn> <DataGridTextColumn Header="Label" Width="200" Binding="{Binding Label}"></DataGridTextColumn> <DataGridTemplateColumn Header="Status" Width="60"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Ellipse Height="13" Name="grdfEllipse" Stroke="Black" Fill="{}" Width="20"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid>

Code Behind:

List<IOInformation> lstIOStatus = new List<IOInformation>(); for (int i = 0; i < channelStatus.Count(); i++) { // var columns = line.Split('\t'); lstIOStatus.Add(new IOInformation { ChannelNo = "Channel " + j++, Label = labeldata[i], MasterStatus = Convert.ToBoolean(channelStatus[i]) }); } this.grdDeviceInfo.ItemsSource = lstIOStatus;

I want to change the Ellipse color to green if it is true, or red if it is false.

最满意答案

您可以使用触发器执行此操作。 以下是关于如何使用它们的链接:

http://www.wpf-tutorial.com/styles/trigger-datatrigger-event-trigger/

您的xaml代码如下所示:

<Ellipse Height="13" Name="grdfEllipse" Stroke="Black" Width="20"> <Ellipse.Style> <Setter Property="Fill" Value="Red"/> <Style TargetType="Ellipse"> <Style.Triggers> <DataTrigger Binding="{Binding yourBinding}" Value="true"> <Setter Property="Fill" Value="Green"/> </DataTrigger> </Style.Triggers> </Style> </Ellipse.Style> </Ellipse>

You can use triggers to do this. Here is a link on how top use them :

http://www.wpf-tutorial.com/styles/trigger-datatrigger-event-trigger/

Your xaml code would look like this :

<Ellipse Height="13" Name="grdfEllipse" Stroke="Black" Width="20"> <Ellipse.Style> <Setter Property="Fill" Value="Red"/> <Style TargetType="Ellipse"> <Style.Triggers> <DataTrigger Binding="{Binding yourBinding}" Value="true"> <Setter Property="Fill" Value="Green"/> </DataTrigger> </Style.Triggers> </Style> </Ellipse.Style> </Ellipse>

更多推荐

lstIOStatus,Width,grdDeviceInfo,电脑培训,计算机培训,IT培训"/> <meta name=&qu

本文发布于:2023-07-22 14:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1220578.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何更改   颜色   Ellipse   gridview   runtime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!