Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF MVVM:用于将ICommand列表绑定到列表框的ItemTemplate_C#_Wpf_Mvvm_Binding_Listbox - Fatal编程技术网

C# WPF MVVM:用于将ICommand列表绑定到列表框的ItemTemplate

C# WPF MVVM:用于将ICommand列表绑定到列表框的ItemTemplate,c#,wpf,mvvm,binding,listbox,C#,Wpf,Mvvm,Binding,Listbox,在MVVM应用程序中,我希望动态显示可在运行时更改的功能按钮。从技术上讲,这并不难,在我的ViewModel中,我有一个可观察到的RelayCommand集合: public ObservableCollection<RelayCommand> CustomCommands {get;set;} publicobservableCollection自定义命令{get;set;} 现在,在Xaml中,我可以将列表框绑定到此集合: <StackPanel Orientation

在MVVM应用程序中,我希望动态显示可在运行时更改的功能按钮。从技术上讲,这并不难,在我的ViewModel中,我有一个可观察到的RelayCommand集合:

public ObservableCollection<RelayCommand> CustomCommands {get;set;}
publicobservableCollection自定义命令{get;set;}
现在,在Xaml中,我可以将列表框绑定到此集合:

<StackPanel Orientation="Horizontal">
  <ListBox ItemsSource="{Binding CustomCommands}">
    <ListBox.ItemsPanel>
      <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal"/>
      </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
      <DataTemplate>
        <wpfhlp:RelayButton DataContext="{Binding}"/>
      </DataTemplate>
    </ListBox.ItemTemplate>
  </ListBox>
</StackPanel>

乍一看,这似乎是可行的。
我的问题是:禁忌顺序被打破了。我希望用户能够从一个按钮跳到另一个按钮,但是列表框可以代替按钮获得用户的焦点,我可以使用箭头键而不是tab键在按钮之间进行选择

我需要ListBox功能来绑定到集合,但我不需要任何其他ListBox功能。
是否有其他面板可以代替列表框使用?

或者我是否可以禁用ListBox功能,使其仅显示所包含的项,而无法在ListBox中选择它们?

如果不需要任何ListBox功能,请尝试使用基本项控件而不是ListBox:

<StackPanel Orientation="Horizontal">
  <ItemsControl ItemsSource="{Binding CustomCommands}">
    <ItemsControl.ItemsPanel>
      <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal"/>
      </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
      <DataTemplate>
        <wpfhlp:RelayButton DataContext="{Binding}"/>
      </DataTemplate>
    </ItemsControl.ItemTemplate>
  </ItemsControl>
</StackPanel>