[英]WPF designer issue referencing enum
因此,在此示例中,我使用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
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.