【问题标题】:WPF ListBox select All items using xaml onlyWPF ListBox 仅使用 xaml 选择所有项目
【发布时间】:2017-07-19 10:09:39
【问题描述】:

我可以只通过 XAML 选择 WPF Listbox 中的所有项目吗?

我也关注了这个问题WPF Listbox and Select All,但它不起作用。 我的 XAML 代码如下:

<ListBox SelectionMode="Multiple" Name="listBox">
    <ListBox.InputBindings>
        <KeyBinding Command="ApplicationCommands.SelectAll" Modifiers="Ctrl" Key="A" />
    </ListBox.InputBindings>
    <ListBox.CommandBindings>
        <CommandBinding Command="ApplicationCommands.SelectAll"  />
    </ListBox.CommandBindings>
    <ListBoxItem>List Item 1</ListBoxItem>
    <ListBoxItem>List Item 2</ListBoxItem>
    <ListBoxItem>List Item 3</ListBoxItem>
    <ListBoxItem>List Item 4</ListBoxItem>
    <ListBoxItem>List Item 5</ListBoxItem>
</ListBox>

是否只能通过 XAMl 进行全选?

【问题讨论】:

  • XAML only 对您意味着什么,因为您使用的是Command?
  • 我的意思是在 c#/vb 中的代码后面没有任何代码。我可以删除命令绑定。
  • 我必须在 poweshell 中使用这个 XAML 视图。所以后面的代码在那里不起作用。

标签: c# wpf xaml listbox


【解决方案1】:

不,ListBox 有自己的SelectAllCommand,但它是私有的,因此您无法绑定到它。它不会为您处理 ApplicationCommands.SelectAll 命令。您需要自己处理CommandBinding 的Executed 事件:

private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
    listBox.SelectAll();
}

XAML 是一种标记语言,而不是一种编程语言。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 2011-10-28
    相关资源
    最近更新 更多