0

我正在使用 x:Bind with mode=OneWay。

<CommandBar
    DefaultLabelPosition="Bottom"
    RelativePanel.RightOf="AutoSuggestBoxSearchItem">
    <AppBarButton
        x:Name="DetailsButton"
        Icon="Contact"
        Label="View details"
        IsEnabled="{x:Bind converters:Converters.IsNotNull(ViewModel.SelectedItem), Mode=OneWay}"/>
    <AppBarButton
        x:Name="DeleteButton"
        Icon="Delete"
        Label="Delete"
        IsEnabled="{x:Bind converters:Converters.IsNotNull(ViewModel.SelectedItem), Mode=OneWay}"/>
    <AppBarSeparator/>
    <AppBarButton
        x:Name="AddButton"
        Icon="Add"
        Label="Add"/>

IsNotNull 检查对象是否不为空。

public class Converters
{
    public static bool  IsNotNull(object value) => value != null;
}

ViewModel.SectedItem 显示数据网格中的选定项。因此,当我在 DataGrid 中选择项目时,应用栏按钮必须将属性 isEnabled 设置为 true。

但是: 顶部的 2 个第一个按钮必须可用,但不可用

4

1 回答 1

1

创建一个属性并将其绑定到 IsEnabled,如下所示 IsEnabled="{x:Bind propertyName)

在属性设置器上使用 OnPropertyChanged("propertyName")

于 2018-10-05T18:44:36.730 回答