[英]Is there any way to put a checkmark beside a context menu in wp7 / silverlight?
我使用Silverlight在wp7應用程序的ContextMenu中有幾個MenuItem。 在特定的情況下,我需要在其中一項旁打勾。
有什么辦法嗎?
如果需要的話,我想在其右側添加一個Image控件。
我什至嘗試這樣做:
CheckBox box = new CheckBox();
menuItem.Items.Add(box);
但是收到了NotImplementedException。
謝謝!
您可以將一個列表框添加到contextmenu,然后將復選框添加到該列表框。 我尚未實施,但您可以嘗試一下。
我找到了一種簡單的方法來使其工作。 我在xaml中將菜單項的Header文本屬性綁定到一個字符串屬性,如果設置了標志,該屬性將添加Unicode選中標記字符(0x2714)。
<toolkit:MenuItem
Header="{Binding InvertedCommandHeader}"
Click="onCommandInvert"
/>
我在數據上下文對象中定義了依賴項屬性,如下所示:
public const string InvertedPropertyTag = "Inverted";
public static readonly DependencyProperty InvertedProperty =
DependencyProperty.Register(
InvertedPropertyTag,
typeof(bool),
typeof(MyData),
new PropertyMetadata(false));
public bool Inverted
{
get
{
return (bool)GetValue(InvertedProperty);
}
set
{
SetValue(InvertedProperty, value);
InvertedCommandHeader = value ?
Strings.IDST_MENUITEM_INVERTED + " \u2714" :
Strings.IDST_MENUITEM_INVERTED;
}
}
public const string InvertedCommandHeaderPropertyTag = "InvertedCommandHeader";
public static readonly DependencyProperty InvertedCommandHeaderProperty =
DependencyProperty.Register(
InvertedCommandHeaderPropertyTag,
typeof(string),
typeof(MyData),
new PropertyMetadata(
Strings.IDST_MENUITEM_INVERTED));
public string InvertedCommandHeader
{
get
{
return (string)GetValue(InvertedCommandHeaderProperty);
}
set
{
SetValue(InvertedCommandHeaderProperty, value);
}
}
選擇菜單項時,我切換了復選標記屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.