[英]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.