C# RibbonGallery项命令单击
使用WPF MVVM的风格。 尝试使用可单击的项目创建RibbonGallery 由于某些原因,我无法获取启动委托命令的项 XAML代码:C# RibbonGallery项命令单击,c#,wpf,xaml,ribboncontrolslibrary,C#,Wpf,Xaml,Ribboncontrolslibrary,使用WPF MVVM的风格。 尝试使用可单击的项目创建RibbonGallery 由于某些原因,我无法获取启动委托命令的项 XAML代码: <RibbonMenuButton LargeImageSource="Images/DeleteUser1.png" Label="Delete"> <RibbonGallery> <RibbonGalleryCategory ItemsS
<RibbonMenuButton LargeImageSource="Images/DeleteUser1.png" Label="Delete">
<RibbonGallery>
<RibbonGalleryCategory ItemsSource="{Binding AvailibleUsers}" Header="User List">
<RibbonGalleryCategory.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="Images/DeleteUser1.png" Width="25"/>
<ContentPresenter Content="{Binding}" Grid.Column="1">
<ContentPresenter.InputBindings>
<MouseBinding MouseAction="LeftClick" Command="{Binding CommandDeleteAllPermissions}"/>
</ContentPresenter.InputBindings>
</ContentPresenter>
</Grid>
</DataTemplate>
</RibbonGalleryCategory.ItemTemplate>
</RibbonGalleryCategory>
</RibbonGallery>
</RibbonMenuButton>
我已经使用一个标准按钮测试了这个命令,它会触发,但是使用特定的XAML代码,我无法在RibbonGallery控件中获得可单击的项
有什么想法吗?图库是一种分类列表,可以检查其项目。它们适用于需要选项菜单时,用户应在其中选中/取消选中项目: 这是数据绑定库和示例视图模型的XAML:
<RibbonMenuButton Label="FooGallery">
<RibbonGallery>
<RibbonGalleryCategory ItemsSource="{Binding GalleryItems}">
<RibbonGalleryCategory.ItemContainerStyle>
<Style TargetType="{x:Type RibbonGalleryItem}">
<Setter Property="Content" Value="{Binding Content}"/>
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
</Style>
</RibbonGalleryCategory.ItemContainerStyle>
</RibbonGalleryCategory>
</RibbonGallery>
</RibbonMenuButton>
如果需要下拉菜单来执行某些命令,则应使用常规的s:
当菜单项静态已知时,应这样做:
<RibbonMenuButton Label="Foo">
<RibbonMenuItem Header="Bar1" Command="{Binding Bar1Command}"/>
<RibbonMenuItem Header="Bar2" Command="{Binding Bar2Command}"/>
<RibbonMenuItem Header="Bar3" Command="{Binding Bar3Command}"/>
</RibbonMenuButton>
其中MenuItems
是这些视图模型的集合:
public class GalleryItem
{
public object Content { get; set; }
public bool IsSelected
{
get { return isSelected; }
set
{
if (isSelected != value)
{
isSelected = value;
// TODO: do something here, when item becomes selected/checked;
// handle property changing instead of commands
}
}
}
private bool isSelected;
}
public class MenuItemVm
{
public object Header { get; set; }
public ICommand Command { get; set; }
}
库是某种分类列表,可以检查其项目。它们适用于需要选项菜单时,用户应在其中选中/取消选中项目: 这是数据绑定库和示例视图模型的XAML:
<RibbonMenuButton Label="FooGallery">
<RibbonGallery>
<RibbonGalleryCategory ItemsSource="{Binding GalleryItems}">
<RibbonGalleryCategory.ItemContainerStyle>
<Style TargetType="{x:Type RibbonGalleryItem}">
<Setter Property="Content" Value="{Binding Content}"/>
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
</Style>
</RibbonGalleryCategory.ItemContainerStyle>
</RibbonGalleryCategory>
</RibbonGallery>
</RibbonMenuButton>
如果需要下拉菜单来执行某些命令,则应使用常规的s:
当菜单项静态已知时,应这样做:
<RibbonMenuButton Label="Foo">
<RibbonMenuItem Header="Bar1" Command="{Binding Bar1Command}"/>
<RibbonMenuItem Header="Bar2" Command="{Binding Bar2Command}"/>
<RibbonMenuItem Header="Bar3" Command="{Binding Bar3Command}"/>
</RibbonMenuButton>
其中MenuItems
是这些视图模型的集合:
public class GalleryItem
{
public object Content { get; set; }
public bool IsSelected
{
get { return isSelected; }
set
{
if (isSelected != value)
{
isSelected = value;
// TODO: do something here, when item becomes selected/checked;
// handle property changing instead of commands
}
}
}
private bool isSelected;
}
public class MenuItemVm
{
public object Header { get; set; }
public ICommand Command { get; set; }
}
请看,我想绑定源项。因为项目源经常更改。 这样做的话,我必须将我的字符串集合修改为一个自定义对象,并使每个对象都包含一个ICommand或其他对象。这还需要让ViewModel程序员更改其内容 因为我只是想改变看法 相反,我只是这样做了
<RibbonMenuButton LargeImageSource="Images/DeleteUser1.png" Label="Delete" ItemsSource="{Binding AvailibleUsers}">
<RibbonGallery Command="{Binding CommandDeleteAllPermissions}">
<RibbonGalleryCategory ItemsSource="{Binding AvailibleUsers}" Header="User List">
<RibbonGalleryCategory.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="Images/DeleteUser1.png" Width="25"/>
<ContentPresenter Content="{Binding}" Grid.Column="1"/>
</Grid>
</DataTemplate>
</RibbonGalleryCategory.ItemTemplate>
</RibbonGalleryCategory>
</RibbonGallery>
</RibbonMenuButton>
我只需要在这里添加命令
<RibbonGallery Command="{Binding CommandDeleteAllPermissions}">
现在,库中的所有项目都会在单击时触发该命令
谢谢大家的帮助,我想绑定项目源代码。因为项目源经常更改。 这样做的话,我必须将我的字符串集合修改为一个自定义对象,并使每个对象都包含一个ICommand或其他对象。这还需要让ViewModel程序员更改其内容 因为我只是想改变看法 相反,我只是这样做了
<RibbonMenuButton LargeImageSource="Images/DeleteUser1.png" Label="Delete" ItemsSource="{Binding AvailibleUsers}">
<RibbonGallery Command="{Binding CommandDeleteAllPermissions}">
<RibbonGalleryCategory ItemsSource="{Binding AvailibleUsers}" Header="User List">
<RibbonGalleryCategory.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="Images/DeleteUser1.png" Width="25"/>
<ContentPresenter Content="{Binding}" Grid.Column="1"/>
</Grid>
</DataTemplate>
</RibbonGalleryCategory.ItemTemplate>
</RibbonGalleryCategory>
</RibbonGallery>
</RibbonMenuButton>
我只需要在这里添加命令
<RibbonGallery Command="{Binding CommandDeleteAllPermissions}">
现在,库中的所有项目都会在单击时触发该命令
谢谢大家的帮助,你能发布更多的视图模型代码吗?还有,你为什么这样做:需要将内容移动到网格的另一部分,这样我就可以有一个groovy图标:)我不确定还需要什么我真的不想发布整个viewmodel。我能告诉你的是,如果我使用并点击这个按钮,它是好的。你能发布更多的ViewModel代码吗?还有,你为什么这样做:需要将内容移动到网格的另一部分,这样我就可以有一个groovy图标:)我不确定还需要什么我真的不想发布整个viewmodel。我可以告诉你的是,如果我使用,我点击这个按钮,它是好的。