0

私はWPFが初めてです。XAML のどこかで立ち往生しています。この XAML コードは機能しています。

<DataGridTextColumn Binding="{Binding Model.Name, UpdateSourceTrigger=PropertyChanged}">
  <DataGridTextColumn.CellStyle>
    <Style TargetType="{x:Type DataGridCell}">
      <Style.Triggers>
        <DataTrigger Value="False"
                     Binding="{Binding DataContext.Model.Error[All],
                                  RelativeSource={RelativeSource FindAncestor,
                                            AncestorType={x:Type DataGridRow}},
                                  Converter={StaticResource IsNull}}">
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type DataGridCell}">
                <Border>
                  <Grid>
                    <ContentPresenter x:Name="_cp" />
                    <Image Source="{DynamicResource Img.Warning}"
                             ToolTip="{Binding DataContext.Model.Error[Name],
                                       RelativeSource={RelativeSource FindAncestor,
                                             AncestorType={x:Type DataGridRow}}" />
                  </Grid>
                </Border>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </DataGridTextColumn.CellStyle>
</DataGridTextColumn>

Image Tooltip Binding で使用するために、最初の行の Binding 情報から「All」、「Name」などの変数文字列を取得したいと考えています。ご覧のとおり、最初の行のバインド情報は "Model.Name" です。Converter を使用して「名前」文字列だけを取得できますが、そのバインディング情報に到達できません。

検索すると、MultiBinding を使用する提案が見つかり、次のコードを書きました。

<DataGridTextColumn Binding="{Binding Model.Name, UpdateSourceTrigger=PropertyChanged}">
  <DataGridTextColumn.CellStyle>
    <Style TargetType="{x:Type DataGridCell}">
      <Style.Triggers>
        <DataTrigger Value="False">
          <DataTrigger.Binding>
            <MultiBinding>
              <MultiBinding.Converter>
                <conv:DictionaryItemConverter />
              </MultiBinding.Converter>
              <Binding Path="DataContext.Model.Error"
                       RelativeSource="{RelativeSource FindAncestor,
                                        AncestorType={x:Type DataGridRow}}" />
              <Binding Path="?????" RelativeSource="?????" />
            </MultiBinding>
          </DataTrigger.Binding>

          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type DataGridCell}">
                <Border>
                  <Grid>
                    <ContentPresenter x:Name="_cp" />
                    <Image Source="{DynamicResource Img.Warning}">
                      <Image.ToolTip>
                        <Binding>
                          ?????
                        </Binding>
                      </Image.ToolTip>
                    </Image
                  </Grid>
                </Border>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </DataGridTextColumn.CellStyle>
</DataGridTextColumn>

しかし、ご覧のとおり、文字列情報を取得するために立ち往生しています。ところで、DataContext.Model.Error は Dictionary クラスのように機能するクラスであり、DictionaryItemConverter はこのクラスから値を取得しています

その結果、私の問題はこれです。

DataTextColumn のバインディング情報を文字列として取得するにはどうすればよいですか?

すべての回答に感謝します。

PS: 英語は私の第一言語ではありません。私が間違っていたら、ごめんなさい。

PS: 私が望むものを示すサンプルを作成しました。ここからダウンロードできます: https://mega.nz/#!oIJXgLxb!eBNqOIdby0UgkKgfqgCOVqYE1O-KwQH7cfEQxk6aCd0

4

1 に答える 1

0

あなたはこれを試すことができます:

    <DataTrigger Value="False">
      <DataTrigger.Binding>
        <MultiBinding>
          <MultiBinding.Converter>
            <conv:DictionaryItemConverter />
          </MultiBinding.Converter>
          <Binding Path="DataContext.Model.Error"
                   RelativeSource="{RelativeSource FindAncestor,
                                    AncestorType={x:Type DataGridRow}}" />

          <Binding RelativeSource="{RelativeSource FindAncestor,
                                    AncestorType={x:Type DataGridCell}}" />
        </MultiBinding>
      </DataTrigger.Binding>

次に、現在のセルに移動し、内BindingDataContextプロパティを検索しますDictionaryItemConverter

しかし、実際には、あまりにも複雑なことをしているように感じます。おそらく、質問を変更して、全体的な目標と ViewModel に関連するプロパティを表示することができます。

于 2016-07-12T14:03:36.127 に答える