我正在尝试创建自己的GridViewColumn,并遇到了一些绑定问题。
有人能给我解释一下为什么下面的头绑定能起作用吗
<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>当它在这里失败时?
<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。
发布于 2013-03-14 18:25:56
在发布问题几分钟后,我在这个thread中找到了我的答案。答案基本上是GridViewColumn不会被添加到可视化树中,所以使用这个可视化树的绑定(例如FindAncestor)不能工作。
因此,我继承了绑定到的元素(例如GridViewColumnHeader)的已加载事件,并在代码隐藏中进行了绑定:
BindingOperations.SetBinding(sender as GridViewColumnHeader, GridViewColumnHeader.ContentProperty, new Binding("Sprache") { Source = this, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay });https://stackoverflow.com/questions/15405228
复制相似问题