1

WPF Databinding の周りの森で迷子になったキャンピングカーです。データバインディングの反転した氷の壁を登る実りある一日でしたが、私はこれで終わりです。例が見つからないか、SNOOP の量が問題の発見に役立っています。願わくば、3 人全員のデータバインド ロック スターが兄弟を助けてくれることを願っています! :)

XML ファイル- 顔と名前は罪のない人を保護するために変更されています

    <?xml version="1.0" encoding="utf-8" ?>
<Mappings>
  <Mapping>
    <Class1>WonderBread</Class1>
    <Class2>Tortilla</Class2>
    <Properties>
      <Property>
        <Jx>name</Jx>
        <Dyn>Name</Dyn>
        <Create>1</Create>
        <Update>0</Update>
      </Property>
      <Property>
        <Jx>Juice</Jx>
        <Dyn>Juice</Dyn>
        <Create>1</Create>
        <Update>0</Update>
      </Property>
      <Property>
        <Jx>Fred</Jx>
        <Dyn>Fred</Dyn>
        <Create>1</Create>
        <Update>0</Update>
      </Property>
      <Property>
        <Jx>Love</Jx>
        <Dyn>Love</Dyn>
        <Create>1</Create>
        <Update>0</Update>
      </Property>
    </Properties>
  </Mapping>
</Mappings>

この XML ファイルをロードして、データグリッドの DataContext に設定する方法。コンストラクタで行います。これは正しく読み込まれます。SNOOP を介して、DataContext で XML ファイルを確認できます。

    // load the ObjectMappingXML file and set as Gridview Context
    XEClassMappings = XElement.Load(ConfigurationManager.AppSettings["ClassMappingXML"]);
    dgMapping.DataContext = XEClassMappings;

コンテンツを表示する XAML コード

        <DataGrid x:Name="dgMapping" ItemsSource="{Binding Path=Elements[Property]}" Height="569">
            <DataGrid.Columns >
                <DataGridTextColumn Header="JxAPI Prop" Binding="{Binding Path=Element[Jx].Value}"/>
                <DataGridTextColumn Header="Dyn Prop" Binding="{Binding Path=Element[Dyn].Value}"/>
            </DataGrid.Columns>
        </DataGrid>

神聖なものすべての名において、私は何を見逃しているのですか?希望に満ちた 8 時間の F5 で、私は途方に暮れました...

4

1 に答える 1

0

プロパティ要素に到達する必要があります。ItemsSource バインディングを以下に変更します。

<DataGrid x:Name="dgMapping" ItemsSource="{Binding Path=Element[Mapping].Element[Properties].Elements[Property]}" Height="569">

それが動作します。

それが役に立てば幸い

于 2013-09-04T19:28:05.260 に答える