0

私はこの答えが好きで、ほとんど私に合っています。

DataTemplateしかし、私のが外部にある場合、どうすればこれを達成できResourceDictionaryますか?

私は Prism を使用しており、次のDataTemplatesようなファイルを使用して、各モジュールごとに (一般的な CRUD ビュー用に)を提供しています。

<ResourceDictionary ... some hidden ns here ... >
    <DataTemplate DataType="{x:Type model:Operation}">
        <vw:OperationView />
    </DataTemplate>
    <DataTemplate DataType="{x:Type model:Customer}">
        <vw:CustomerView />
    </DataTemplate>
</ResourceDictionary>

次に、この回答を使用してシェルアプリにマージしResourceDictionariesます。そのコードを持つデフォルトの CRUD ビューがあります。

<ContentControl Content="{Binding MyGenericObject}" />

それContentControlは自動的に正しいビューを引き出します。正常に動作していますが、各ビューのオブジェクトのプロパティをバインドする方法を知りたいです。

これは、これらのビュー (OperationView.xaml) のサンプルです。

<UserControl x:Class="TryERP2.Cadastro.View.OperationView"
             ... some hidden NS ... >
    <StackPanel>
        <Label Content="Id" />
        <TextBox Text="{Binding ????WHAT????}" />
        <Label Content="Description" />
        <TextBox Text="{Binding ????WHAT????}" />
    </StackPanel>
</UserControl>

これらのプロパティをバインドするにはどうすればよいですか?

4

2 に答える 2

2

DataContext背後OperationViewはタイプのオブジェクトになるため、必要Operationなプロパティにバインドするだけです。Operation

<!-- DataContext will be model:Operation per your DataTemplate -->
<UserControl x:Class="TryERP2.Cadastro.View.OperationView"
             ... some hidden NS ... >
    <StackPanel>
        <Label Content="Id" />
        <TextBox Text="{Binding Id}" />
        <Label Content="Description" />
        <TextBox Text="{Binding Description}" />
    </StackPanel>
</UserControl>
于 2012-01-24T13:48:41.600 に答える
1

はモデルオブジェクトであるためDataContextUserControl次のようにそのプロパティに直接バインドできます。

Text="{Binding SomeProperty}"

(パスのみが指定されている場合、バインディングはに関連しています。リンクした回答では、プリミティブ文字列であるそれ自体にバインディングを設定DataContextすることを意図していたことに注意してください。これは、プロパティパスのような単純なバインディングを使用して行うことはできません。実際の物件をターゲットにすることを指定する必要があります)TwoWayDataContext{Binding .}

于 2012-01-24T13:49:32.397 に答える