我在我的DataGridRowHeader模板中有一个按钮,定位在列的右边。
这个布局的好处是,当您单击按钮时,它不会选择行,就像您在列中定位它一样。
我现在发现的问题是,我试图绑定该行的对象属性,例如在按钮的ToolTip中。它一直是空白的,即使我把它硬编码了。Visibility上的同样类型的绑定也很好。
我怎样才能修复ToolTip?
<DataGrid.RowHeaderTemplate>
<DataTemplate>
<Grid>
<Button x:Name="btnSelectParent"
Template="{StaticResource SelectParentButtonStyle}"
Height="15" Width="15"
Margin="0,0,-669,0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
ToolTipService.ShowOnDisabled="True"
Visibility="{Binding DataContext.ShowSelectParentBtn, RelativeSource={RelativeSource AncestorType=DataGridRow}, Converter={StaticResource bool2VisibilityConverter}}" >
<Button.ToolTip>
<TextBlock TextAlignment="Left"
Foreground="Black"
FontWeight="Normal"
Text="{Binding DataContext.ParentBtnMessage, RelativeSource={RelativeSource AncestorType=DataGridRow}}"/>
</Button.ToolTip>
</Button>
</Grid>
</DataTemplate>
</DataGrid.RowHeaderTemplate>发布于 2017-09-06 10:19:29
DataGridRow不是RowHeaderTemplate中Button的视觉祖先,但DataGridRowHeader是:
Visibility="{Binding DataContext.ShowSelectParentBtn, RelativeSource={RelativeSource AncestorType=DataGridRowHeader}, Converter={StaticResource bool2VisibilityConverter}}"第二个问题是Tooltip驻留在自己的元素树中。您可以通过将Button的Button属性绑定到DataGridRowHeader的DataContext,然后使用Tooltip的PlacementTarget绑定到该属性来解决这个问题。
<Button x:Name="btnSelectParent"
...
Tag="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType=DataGridRowHeader}}">
<Button.ToolTip>
<ToolTip>
<TextBlock TextAlignment="Left"
Foreground="Black"
FontWeight="Normal"
Text="{Binding PlacementTarget.Tag.ParentBtnMessage, RelativeSource={RelativeSource AncestorType=ToolTip}}"/>
</ToolTip>
</Button.ToolTip>
</Button>https://stackoverflow.com/questions/46069487
复制相似问题