首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将DataGridRowHeader按钮工具提示绑定到行对象属性

将DataGridRowHeader按钮工具提示绑定到行对象属性
EN

Stack Overflow用户
提问于 2017-09-06 07:42:39
回答 1查看 104关注 0票数 0

我在我的DataGridRowHeader模板中有一个按钮,定位在列的右边。

这个布局的好处是,当您单击按钮时,它不会选择行,就像您在列中定位它一样。

我现在发现的问题是,我试图绑定该行的对象属性,例如在按钮的ToolTip中。它一直是空白的,即使我把它硬编码了。Visibility上的同样类型的绑定也很好。

我怎样才能修复ToolTip?

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-06 10:19:29

DataGridRow不是RowHeaderTemplateButton的视觉祖先,但DataGridRowHeader是:

代码语言:javascript
复制
Visibility="{Binding DataContext.ShowSelectParentBtn, RelativeSource={RelativeSource AncestorType=DataGridRowHeader}, Converter={StaticResource bool2VisibilityConverter}}"

第二个问题是Tooltip驻留在自己的元素树中。您可以通过将ButtonButton属性绑定到DataGridRowHeaderDataContext,然后使用TooltipPlacementTarget绑定到该属性来解决这个问题。

代码语言:javascript
复制
<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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46069487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档