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}" />
相关推荐
凌镜icecraft4 天前
我改文件扩展名的时候那个警告弹窗再也不会弹出来了
windows·c#·wpf·explorer
光泽雨8 天前
控件Password附加属性
wpf
samble13 天前
从零搭建半导体设备上位机(十二):参数设置页,表单校验、范围校验与配方联动
wpf·数据校验·validationrule
samble21 天前
从零搭建半导体设备上位机(九):拖拽与交互,Adorner、DragDrop 与晶圆拖放信息
wpf·拖拽·adorner
郝学胜-神的一滴23 天前
AI 编程智能体 27:吃透MCP通信机制
人工智能·python·langchain·wpf·numpy·scikit-learn
波力海苔夹心脆67523 天前
C# WPF 资源字典详解:ResourceDictionary、MergedDictionaries 与自定义控件案例
开发语言·c#·wpf·入门教程·resource·资源字典
陈仓主教23 天前
# WPF CheckBox 控件详解与使用—WPF 中的控件(6)--复选框控件(CheckBox)
wpf
光泽雨1 个月前
WPF 音视频四大核心方案对比
wpf·音视频
浪扼飞舟1 个月前
WPF(数据绑定)
wpf
samble1 个月前
从零搭建半导体设备上位机(四):单实例、启动流程与配置文件,App 里那 526 行到底在干什么
wpf·配置文件·单实例