小编ken*_*eno的帖子

wpf 数据触发器绑定到方法

我有一个返回 true 或 false 的方法。

我希望将此方法绑定到我的 DataTrigger

       <DataGrid ItemsSource="{Binding Source={StaticResource SmsData}, XPath=conv/sms}">
        <DataGrid.RowStyle>
            <Style TargetType="{x:Type  DataGridRow}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=check}" Value="true">
                        <Setter Property="Foreground" Value="Black" />
                        <Setter Property="Background" Value="Blue" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </DataGrid.RowStyle>
    </DataGrid>
Run Code Online (Sandbox Code Playgroud)

如果返回值为“true”,则执行设置器...

我的代码:

public MainWindow()
{
    DataContext = this;
    InitializeComponent();
}


public string check
{
    get
    {
       return "true";
    }
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能让它工作?我现在收到错误(在运行时,不会使程序崩溃): BindingExpression 路径错误:在“对象”“XmlElement”上找不到“检查”属性

c# wpf bind datatrigger

5
推荐指数
1
解决办法
4154
查看次数

标签 统计

bind ×1

c# ×1

datatrigger ×1

wpf ×1