Enable/Disable 列表框被选中时的按钮
Enable/Disable Button When Listbox is Selected
我有一个列表框
<ListBox Background="WhiteSmoke"
Name="LstComponents"
ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ComponentID}" />
<TextBlock Text=" - " />
<TextBlock Text="{Binding ComponentName}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
和几个按钮
<Button Content="Add New Components"
Name="BtnAdd"
Margin="5"
Click="BtnAdd_Click" />
<Button Content="Update Components"
Name="BtnUpdate"
Grid.Column="1"
Margin="5"
Click="BtnUpdate_Click" />
<Button Content="Delete Components"
Grid.Column="2"
Name="BtnDelete"
Margin="5"
Click="BtnDelete_Click" />
现在我希望更新和删除按钮在加载时被禁用,而如果列表框中的列表项被选中则它应该启用。
我不想为其编写代码。请建议?我如何才能在 XAML
中完成此任务
您可以使用
IsEnabled="{Binding ElementName=ListBoxName, Path=SelectedItems.Count}"
使其发挥作用。
我有一个列表框
<ListBox Background="WhiteSmoke"
Name="LstComponents"
ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ComponentID}" />
<TextBlock Text=" - " />
<TextBlock Text="{Binding ComponentName}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
和几个按钮
<Button Content="Add New Components"
Name="BtnAdd"
Margin="5"
Click="BtnAdd_Click" />
<Button Content="Update Components"
Name="BtnUpdate"
Grid.Column="1"
Margin="5"
Click="BtnUpdate_Click" />
<Button Content="Delete Components"
Grid.Column="2"
Name="BtnDelete"
Margin="5"
Click="BtnDelete_Click" />
现在我希望更新和删除按钮在加载时被禁用,而如果列表框中的列表项被选中则它应该启用。
我不想为其编写代码。请建议?我如何才能在 XAML
中完成此任务您可以使用
IsEnabled="{Binding ElementName=ListBoxName, Path=SelectedItems.Count}"
使其发挥作用。