我创建了一个类
public class ContextMenuSetting {
public bool ContextMenuAllowed { get; set; }
public string GridKey { get; set; }
}
还有一个 AttachedProperty,例如:
public static readonly DependencyProperty ContextMenuSettingsProperty = DependencyProperty.RegisterAttached("ContextMenuSettings", typeof(ContextMenuSetting), typeof(BarItemLink), null);
public static void SetContextMenuSettings(this BarItemLink target, ContextMenuSetting contextMenuSetting) {
target.SetValue(ContextMenuSettingsProperty, contextMenuSetting);
}
public static ContextMenuSetting GetContextMenuSettings(this DependencyObject target) {
return (ContextMenuSetting)target.GetValue(ContextMenuSettingsProperty);
}
我现在在 xaml 中使用了 BarItemLink:
<dxb:BarItemLink BarItemName="newActivity" />
有人可以帮助我,我现在如何为 BarButtonLink 的 AttachedProperty ContextMenuSettings 设置一个值?
编辑 - 更新解决方案:
在 Charleh 的帮助下,我找到了解决方案:
<dxb:BarItemLink BarItemName="newActivity">
<pcce:BarItemLinkExtensions.ContextMenuSettings >
<pcce:ContextMenuSettings ContextMenuAllowed="True" GridKey="hallo"/>
</pcce:BarItemLinkExtensions.ContextMenuSettings>
</dxb:BarItemLink>