Wpf 以编程方式在MVVM中添加按钮,但命令不';行不通
我试图动态添加按钮,但命令不起作用 我犯了个错误 已为ItemsControl容器类型的项忽略ItemTemplate和ItemTemplateSelector;Type='RadRibbonButton'Wpf 以编程方式在MVVM中添加按钮,但命令不';行不通,wpf,mvvm,telerik,Wpf,Mvvm,Telerik,我试图动态添加按钮,但命令不起作用 我犯了个错误 已为ItemsControl容器类型的项忽略ItemTemplate和ItemTemplateSelector;Type='RadRibbonButton' ... ButtonCommand=新的DelegateCommand(ExecuteCommand); 私有void ExecuteCommand() { ... } 检查它是否在调试模式下到达命令 您的ButtonsCollection是依赖项属性吗?你提高零钱了吗 您不应该向but
...
ButtonCommand=新的DelegateCommand(ExecuteCommand);
私有void ExecuteCommand()
{
...
}
<telerik:RadRibbonGroup>
...
<telerik:RadRibbonGroup.DataContext>
<vm:Group1/>
</telerik:RadRibbonGroup.DataContext>
<ItemsControl ItemsSource="{Binding ButtonsCollection}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding}" Command="{Binding DataContext.ButtonCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadRibbonGroup}}}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</telerik:RadRibbonGroup>
ButtonCommand= new DelegateCommand(ExecuteCommand);
private void ExecuteCommand()
{
...
}