Có ai biết tại sao điều này sẽ tạo ra một XamlParseException "Không thể thêm nội dung của loại 'System.Windows.Controls.ContextMenu' đến một đối tượng của loại 'System.Object'":ContextMenu trong Phong cách setter
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas ClipToBounds="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Remove" />
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
Và sau đây hoạt động tốt?
<ItemsControl>
<ItemsControl.Resources>
<ContextMenu x:Key="NodeContextMenu">
<MenuItem Header="Remove" />
</ContextMenu>
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas ClipToBounds="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="ContextMenu" Value="{StaticResource NodeContextMenu}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
thật kỳ lạ. phải là một cái gì đó để làm với giá trị mong đợi một đối tượng nhưng tôi không thấy lý do tại sao mà sẽ gây ra một ngoại lệ ... Nếu đây là trong Expression Blend nó có thể là giá trị mở lại tất cả mọi thứ bởi vì nó có thể chơi lên đôi khi –
của nó trong visual studio 2008 trong khi ứng dụng được thực hiện, tôi đã di chuyển menu ngữ cảnh sang tài nguyên và nó hoạt động nhưng tôi nghĩ nó nên hoạt động với setter cũng có thể là lỗi – serine
Đây là vấn đề tương tự như với [câu hỏi này] (http: // stackoverflow. com/questions/1495489/không thể cài đặt-hệ thống-cửa sổ-điều khiển-menuitem-icon-thru-a-setter). – CodeNaked