gpt4 book ai didi

c# - RibbonGallery 项目命令单击

转载 作者:太空宇宙 更新时间:2023-11-03 21:19:53 25 4
gpt4 key购买 nike

使用 WPF MVVM 风格。尝试使用可点击的项目创建 RibbonGallery由于某种原因,我无法获得启动我的委托(delegate)命令的项目

XAML 代码:

<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>

数据上下文已设置为 View 模型。 View 模型:

    public DelegateCommand CommandDeleteAllPermissions { get { return new DelegateCommand(Delegated_DeleteAllPermissions); } }

private void Delegated_DeleteAllPermissions(object obj)
{
\\todo:stuff
}

我已经使用标准按钮测试了这个命令并且它触发了,但是使用特定的 XAML 代码我无法在我的 RibbonGallery 控件中获得可点击的项目。

有什么想法吗?

最佳答案

画廊是某种分类列表,可以检查其项目。它们适用于当您需要选项菜单时,用户应在其中选中/取消选中项目:

enter image description here

这是用于数据绑定(bind)图库和示例 View 模型的 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>

这里 GalleryItems 是这些 View 模型的集合:

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;
}

如果您需要下拉菜单来执行一些命令,那么您应该使用常规的RibbonMenuItem。小号:

enter image description here

当菜单项静态已知时,应该这样做:

            <RibbonMenuButton Label="Foo">
<RibbonMenuItem Header="Bar1" Command="{Binding Bar1Command}"/>
<RibbonMenuItem Header="Bar2" Command="{Binding Bar2Command}"/>
<RibbonMenuItem Header="Bar3" Command="{Binding Bar3Command}"/>
</RibbonMenuButton>

当对菜单项使用 ItemsSource 时,XAML 将如下所示:

            <RibbonMenuButton Label="Foo" ItemsSource="{Binding MenuItems}">
<RibbonMenuButton.ItemContainerStyle>
<Style TargetType="{x:Type RibbonMenuItem}">
<Setter Property="Header" Value="{Binding Header}"/>
<Setter Property="Command" Value="{Binding Command}"/>
</Style>
</RibbonMenuButton.ItemContainerStyle>
</RibbonMenuButton>

其中 MenuItems 是这些 View 模型的集合:

public class MenuItemVm
{
public object Header { get; set; }
public ICommand Command { get; set; }
}

关于c# - RibbonGallery 项目命令单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31531740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com