[英]Bind enum from external class in same namespace to ListBox (or whatever) in WPF (C# and XAML)
我看了看,但是什么都沒有。
說我有這樣的事情:
namespace A{
partial class B : Window {
//some definitions
}
class E {
public enum en {a, b, c}
}
}
然后在XAML中:
<Window x:Class="A.B"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:A">
<Window.Resources>
<ObjectDataProvider MethodName="GetValues"
ObjectType="{x:Type sys:Enum}"
x:Key="vals">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="en" /> <<<this line
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
..rest of XAML ...
</window>
現在標記的行給我錯誤:
Type 'en' was not found.
如果我將其更改為相同
local:en
E+en
local:E+en
我該如何解決這個問題? 非常感謝
試試這個
<Window x:Class="WpfApplication12.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication12"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<ObjectDataProvider x:Key="dataFromEnum"
MethodName="GetValues"
ObjectType="{x:Type System:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:Window1+en" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<Grid>
<ListView ItemsSource="{Binding Source={StaticResource dataFromEnum}}"
Margin="10,10,10,0"
Height="80"
VerticalAlignment="Top" />
<ComboBox ItemsSource="{Binding Source={StaticResource dataFromEnum}}"
Margin="10,0,10,80"
Height="25"
VerticalAlignment="Bottom" />
<ListBox ItemsSource="{Binding Source={StaticResource dataFromEnum}}"
Margin="10,0,10,12"
Height="93"
VerticalAlignment="Bottom" />
</Grid>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
public enum en { a, b, c }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.