簡體   English   中英

檢查是否選擇了ListView項目

[英]Check if ListView item selected

我想讓Button的IsEnabled屬性檢查ListView是否具有選擇。 有什么方法可以檢查是否僅使用XAML選擇了ListView項? 就像是:

<Button Content="Remove" Command="{Binding RemoveConditionCommand}"
                CommandParameter="{Binding ElementName=conditionsListView, Path=SelectedItem}"
                IsEnabled="{Binding ElementName=conditionsListView, Path=IsSelected}"
                />

您可以使用DataTrigger來實現。 如果ListView的selectedItem為null,則將IsEnabled設置為false。

樣品:

<Button>
    <Button.Style>
        <Style TargetType="Button">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=SelectedItem,
                                               ElementName=conditionsListView}"
                             Value="{x:Null}">
                    <Setter Property="IsEnabled" Value="False"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM