首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么GridViewColumn中的FindAncestor绑定不起作用?

为什么GridViewColumn中的FindAncestor绑定不起作用?
EN

Stack Overflow用户
提问于 2013-03-14 17:16:28
回答 1查看 1.4K关注 0票数 2

我正在尝试创建自己的GridViewColumn,并遇到了一些绑定问题。

有人能给我解释一下为什么下面的头绑定能起作用吗

代码语言:javascript
复制
<GridViewColumn x:Class="interneProzesse_UebersetzungstoolNS.TranslateGridViewColumn"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:conv="clr-namespace:interneProzesse_UebersetzungstoolNS.Converter"
         xmlns:hk="clr-namespace:interneProzesse_UebersetzungstoolNS.Hilfsklassen"
         xmlns:local="clr-namespace:interneProzesse_UebersetzungstoolNS"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300"Header="{Binding RelativeSource={RelativeSource Self}, Path=Sprache, UpdateSourceTrigger=PropertyChanged}">
</GridViewColumn>

当它在这里失败时?

代码语言:javascript
复制
<GridViewColumn x:Class="interneProzesse_UebersetzungstoolNS.TranslateGridViewColumn"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:conv="clr-namespace:interneProzesse_UebersetzungstoolNS.Converter"
         xmlns:hk="clr-namespace:interneProzesse_UebersetzungstoolNS.Hilfsklassen"
         xmlns:local="clr-namespace:interneProzesse_UebersetzungstoolNS"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<GridViewColumn.Header>
    <GridViewColumnHeader Content="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:TranslateGridViewColumn}}, Path=Sprache, UpdateSourceTrigger=PropertyChanged}"/>
</GridViewColumn.Header>
<GridViewColumn>

Sprache是我的TranslateGridViewColumn的一个属性,它继承自GridViewColumn。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-14 18:25:56

在发布问题几分钟后,我在这个thread中找到了我的答案。答案基本上是GridViewColumn不会被添加到可视化树中,所以使用这个可视化树的绑定(例如FindAncestor)不能工作。

因此,我继承了绑定到的元素(例如GridViewColumnHeader)的已加载事件,并在代码隐藏中进行了绑定:

代码语言:javascript
复制
BindingOperations.SetBinding(sender as GridViewColumnHeader, GridViewColumnHeader.ContentProperty, new Binding("Sprache") { Source = this, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15405228

复制
相关文章

相似问题

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