cuốn sách gpt4 ai đã làm

c# - 如果源绑定(bind)适用,如何访问快速访问工具栏命令 `Add to Quick Access Tool`

In lại Tác giả: Hồ Xil 更新时间:2023-11-01 08:47:12 27 4
mua khóa gpt4 Nike

如果我已经为它绑定(bind)了集合,我该如何添加 RibbonLibrary 默认的快速访问项容器。当我从 UI 添加快速访问工具项时,它会抛出 Operation is not valid while ItemSource is in use in use.


































ObservableCollection _MenuItems;
ObservableCollection _QuickMenuItems;

public ObservableCollection MenuItems
{
get { return _MenuItems; }
}
public ObservableCollection QuickMenuItems
{
get { return _QuickMenuItems; }
}
public class RibbonItem
{
public RibbonItem(string label, string imageUri, ICommand command, string ribbonId)
{
Label = label;
ImageUri = imageUri;
Command = command;
}

public string Label { get; private set; }

public string ImageUri { get; private set; }

public ICommand Command { get; private set; }

public string RibbonId { get; private set; }
}

错误而

nhập mô tả hình ảnh ở đây

nhập mô tả hình ảnh ở đây
如果不清楚,请添加评论。

câu trả lời hay nhất

问题是 ContextMenu 正在尝试使用 ItemCollection.Add() 将项目添加到集合中,但是如果 ItemsSource 被用来填充集合而不支持此方法,并且该方法将抛出异常。

查看源代码:ItemCollection.cs

一种解决方案是隐藏 ContextMenu 以避免调用其不受支持的功能,或者尝试将其替换为您自己的自定义 ContextMenu,它绑定(bind)到 ViewModel 上的命令并更新 QuickMenuItems。

可能存在某种使用附加属性的黑客行为。

关于c# - 如果源绑定(bind)适用,如何访问快速访问工具栏命令 `Add to Quick Access Tool`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31564211/

27 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress