我目前正在尝试创建动态创建的上下文菜单。我目前正在上下文菜单中将ObservableCollection<MenuItem>
绑定到ItemsSource
属性。我现在想要根据我选择的内容在菜单打开时设置列表中项目的可见性
我尝试从这样的MenuItem
继承
public class CtContextMenuItem : MenuItem
{
public delegate Visibility VisibilityDelegate();
public VisibilityDelegate IsVisibleDelegate = null;
}
我想在打开上下文菜单时将Visibility
设置为VisibilityDelegate
的结果,但我找不到{{1}上调用的任何事件或方法当上下文菜单打开时
有没有办法做到这一点,还是我必须在听MenuItem
的函数中创建菜单的所有项目?
答案 0 :(得分:0)
将Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNamespace("MAPI")
Set objContactsFolder = objNS.GetDefaultFolder(olFolderContacts)
Set objItems = objContactsFolder.Items
For Each obj In objItems
'Test for contact and not distribution list
If obj.Class = olContact Then
Set objContact = obj
With objContact
If .Email1Address <>"" Then
'I want to add the SMTP-Address after the .LastNameAndFirstName of a User
strFileAs = .LastNameAndFirstName
.Email1DisplayName= strFileAs
.Save
End If
End With
End If
Err.Clear
Next
绑定到ItemsSource
类型具有ObservableCollection<CtContextMenuItem>
或CtContextMenuItem
属性的Visibility
,您可以将其绑定在您的XAML中。像这样:
bool
public class CtContextMenuItem
{
public Visibility IsVisible { get; set; }
}