WPF 改变根据某一列条件改变行样式

如图,实现当轴运动中的时候,字体加粗,并且前景色设置为红色;

参考:WPF RadGridView Style Selectors RowStyleSelector - Telerik UI for WPF

主要就三个步骤:

第一步,定义后台的StyleSelector继承类:

cs 复制代码
public class IsMovingStyle : StyleSelector
{
    public override Style SelectStyle(object item, DependencyObject container)
    {
        if (item is AxisStatusProxy axis)
        {
            if (axis.IsMoving)
            {
                return MovingStyle;
            }
            else
            {
                return MotionlessStyle;
            }
        }
        return null;
    }
    public Style MovingStyle { get; set; }
    public Style MotionlessStyle { get; set; }
}

第二步,xaml中设计后台定义的样式:

XML 复制代码
<telerik:RadDocumentPane.Resources>
    <local:IsMovingStyle x:Key="MovingStyle">
        <local:IsMovingStyle.MovingStyle>
            <Style BasedOn="{StaticResource GridViewRowStyle}" TargetType="telerik:GridViewRow">
                <Setter Property="Foreground" Value="DarkRed" />
                <Setter Property="FontWeight" Value="Bold" />
                <Setter Property="FontSize" Value="22" />
            </Style>
        </local:IsMovingStyle.MovingStyle>
        <local:IsMovingStyle.MotionlessStyle>
            <Style BasedOn="{StaticResource GridViewRowStyle}" TargetType="telerik:GridViewRow" />
        </local:IsMovingStyle.MotionlessStyle>
    </local:IsMovingStyle>
</telerik:RadDocumentPane.Resources>

注意:要添加BasedOn="{StaticResource GridViewRowStyle}"

第三步,控件中引用:

XML 复制代码
	<telerik:RadGridView AlternateRowStyleSelector="{StaticResource StadiumCapacityStyle}" />
相关推荐
dalong1017 小时前
WPF:DataGrid样式
wpf
samble3 天前
从零搭建工业控制系统(二十二):线程安全与并发控制
c#·wpf·并发·mvvm·线程安全·工业控制
姜穆澜3 天前
OneID 从 0 到 1 完整生产案例(三)
大数据·wpf
dalong103 天前
WPF:MVVM 示例
大数据·wpf
samble3 天前
从零搭建工业控制系统(二十一):状态管理系统——中心状态对象设计
c#·wpf·mvvm·状态管理·工业控制
mengge.cloud3 天前
存储技术基础小白教程
linux·运维·服务器·wpf·存储
DreamLife☼4 天前
复杂Agent系统架构设计
系统架构·wpf·agent·组件·设计·构架·说明
SamChan904 天前
PDF翻译服务端到端基准测试:4款主流方案的吞吐量、延迟、内存占用对比
服务器·网络·python·ai·pdf·wpf
bugcome_com4 天前
Avalonia 控件模板实战:从 WPF 迁移自定义 Button 样式的完整指南
wpf