【问题标题】:how to bind IsEnabled to property of vm in xaml for button in DataTemplate?如何将 IsEnabled 绑定到 xaml 中的 vm 属性以获取 DataTemplate 中的按钮?
【发布时间】:2015-12-06 11:32:08
【问题描述】:

我的telerik:GridViewDataColumn.CellTemplate xaml 中有带有DataTemplate 的按钮。 我想将 xaml 中的 IsEnabled 属性绑定到我的视图模型中的道具。 我的道具在 viewmodel 中填充了正确的值,但没有显示 xaml 中的更改。如何做到这一点?

<telerik:GridViewDataColumn.CellTemplate>
      <DataTemplate>
             <Button Content="Edit"
                     VerticalAlignment="Center"
                     Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView }},Path=DataContext.SendDateCommand}"
                     CommandParameter="{Binding}" IsEnabled="{Binding IsSetSendDate,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"/>
      </DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>

【问题讨论】:

  • 调试程序时输出窗口是否有绑定失败?
  • @Mahsa Dehghanpour 为什么要使用 Mode=OneWay,我认为它必须是 TwoWay...

标签: c# wpf xaml mvvm telerik


【解决方案1】:

首先,将 IsEnabled 的 Mode 更改为 TwoWay 应该会有所帮助。我还会检查以确保 IsSetSendDate 被声明为 public 并且在你的类中有一个 Getter 和 Setter。还要确保为 xaml 设置了 DataContext,方法是使用 &lt;Window.Resources&gt; 标记声明或在 xaml.cs 构造函数中设置 DataContext。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-22
    • 1970-01-01
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    • 2022-01-05
    相关资源
    最近更新 更多