【问题标题】:WinRT XAML IsEnabled fires only onceWinRT XAML IsEnabled 仅触发一次
【发布时间】:2013-08-23 13:41:10
【问题描述】:

我在 AppBar 上有一个按钮,当 ViewModel 中的属性变为 true 时,我已将其设置为启用。出于某种原因,仅在第一次显示 AppBar 时才检查 IsEnabled 绑定。我错过了什么吗?

这是我在视图中的按钮 XAML(为清楚起见,省略了 AppBar xaml):

<Button  Style="{StaticResource DocumentAppBarButtonStyle}" AutomationProperties.Name="Approve" 
  Command="{Binding ApproveTimesheetCommand, Mode=OneWay}" 
  IsEnabled="{Binding IsAbleToProcessTimesheet, Mode=OneWay}" />

这是我在 ViewModel 中的属性:

public bool IsAbleToProcessTimesheet
{
    get
    {
        return SelectedTimesheets.Count() > 0;
    }
}

在属性上设置断点表明它仅在第一次显示 App Bar 时被调用。显示 App Bar 的后续调用不会触发对 IsEnabled 属性的检查。

您是否需要设置一些东西来让 XAML 在每次显示 AppBar 时调用该属性?

任何帮助将不胜感激。

【问题讨论】:

  • 您必须通知某处的属性更改,以便刷新 UI。最好在同一个地方更改集合。

标签: c# winrt-xaml mvvm-light


【解决方案1】:

您必须使用 SetProperty 方法为 IsAbleToProcessTimesheet 定义 SET。您可以使用 INotifyPropertyChanged

从抽象类 BindableBase 继承

【讨论】:

    猜你喜欢
    • 2016-12-16
    • 1970-01-01
    • 2011-08-13
    • 2020-08-25
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 2018-09-27
    • 2015-04-21
    相关资源
    最近更新 更多