mam DataGrid
i jeden z DataGrid
kolumn wygląda toBinding właściwość DataGridCell ToolTip do wartości DataGridCell
<DataGridTextColumn Header="Value"
Binding="{Binding Value, Converter={StaticResource BooleanToYesNoConverter}}"
x:Name="_col2"
IsReadOnly="True"
CanUserSort="False"
Width="*">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="ToolTip" Value="{Binding Value, Converter={StaticResource BooleanToYesNoConverter}}" />
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
Problem jest zmuszony do korzystania BooleanToYesNoConverter
konwerter dwukrotnie. Oznacza to, że metoda Convert
zostanie wywołana dwukrotnie. Dlatego chcę zoptymalizować mój kod. I chcesz związać wartość właściwości ToolTip
bezpośrednio z wartością komórki.
Próbowałem podejście przy użyciu ElementName
-s. Ale nie mam pojęcia, co należy określić w właściwości wiązania.
<DataGridTextColumn Header="Value"
Binding="{Binding Value, Converter={StaticResource BooleanToYesNoConverter}}"
x:Name="_col2"
IsReadOnly="True"
CanUserSort="False"
Width="*">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="ToolTip" Value="{Binding ElementName=_col2, Path=???}" />
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
Próbowałem użyć DataGridTemplateColumn
zamiast DataGridTextColumn
, ale to nie podlega programowi pracy też.
<DataGridTemplateColumn CanUserSort="False"
Header="Значение"
Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Value, Converter={StaticResource BooleanToYesNoConverter}}"
Name="_textBlock"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="ToolTip" Value="{Binding RelativeSource ElementName=_textBlock, Path=Text}" />
</Style>
</DataGridTemplateColumn.CellStyle>
</DataGridTemplateColumn>
Jak mogę rozwiązać moje zadanie. Czy to w ogóle możliwe?
Działa dobrze. Dzięki. – monstr
Btw, "Treść" jest typem właściwości obiektu. 'Obiekt' nie ma właściwości' Tekst'. Czy wiesz, jaki typ obiektu ma własność 'Text'? Innymi słowy, do jakiego typu należy własność 'Text'? Jest to interesujące i nie oczywiste. – monstr
Tak, masz rację. W ContentPresentor DataGridCell ma TextBlock i ta TextBlock ma właściwość Text. Zrozumiałeś? –