因此,我在此示例中使用 staticextension 引用了一个枚举,它在运行时工作正常,但由于错误“无法创建类型为'StaticExtension' 的实例”而在设计时失败。
我理解这意味着它认为它需要一个枚举类型的实例来实际引用它。但是,枚举在窗口中被定义为静态,所以我不明白它为什么会出现问题。
有什么合理的方法可以让设计师继续工作吗?到目前为止,我发现的最接近的是将它放在 objectdataprovider 中并创建方法来返回枚举值。在幕后,这基本上是在创建一个对象来引用静态类型,而且仅仅将枚举值拉出来似乎工作量太大。这里的目标只是能够引用单个枚举类型并显示它们。
<Window
x:Class="DaedalusGraphViewer.GraphViewerWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:DaedalusGraphViewer="clr-namespace:DaedalusGraphViewer">
<StackPanel>
<Label Content="testtesttest">
<Label.ContextMenu>
<ContextMenu>
<MenuItem Header="{x:Static DaedalusGraphViewer:GraphViewerWindow+Test.test1}"/>
</ContextMenu>
</Label.ContextMenu>
</Label>
</StackPanel>
</Window>
C#:
using System.Windows;
namespace DaedalusGraphViewer
{
/// <summary>
/// Interaction logic for GraphViewerWindow.xaml
/// </summary>
public partial class GraphViewerWindow : Window
{
public GraphViewerWindow()
{
InitializeComponent();
Application.Current.MainWindow = this;
}
public enum Test
{
test1, test2
}
}
}