3

正常に{Binding Path=CollectionProperty[2]}動作しますが、列挙型で動作させることはできません{Binding Path=CollectionProperty[SomeEnum.Value2]}。可能であれば、そのための適切な構文は何でしょうか? ありがとう。

4

2 に答える 2

3

列挙値を飾り気のない文字列として指定するだけです。例:

public enum Foo
{
    Value1,
    Value2
}

public class MainWindowVm
{
    public string this[Foo foo]
    {
        get { return Enum.GetName(typeof(Foo), foo); }
    }
}

次のように列挙値を指定します。

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication1"
        Title="MainWindow" Height="350" Width="525">

    <Window.DataContext>
        <local:MainWindowVm/>
    </Window.DataContext>

    <Grid>
        <TextBlock Text="{Binding Path=[Value1]}"/>
    </Grid>

</Window>

XAML パーサーには、提供された文字列をターゲット列挙型でサポートされている値にマップするサポートが組み込まれているため、x:Static マークアップ拡張機能は必要ありません。

于 2013-09-17T12:46:28.673 に答える