为什么FindAncestor结合在GridViewColumn不工作? [英] Why is FindAncestor binding not working in GridViewColumn?

查看:152
本文介绍了为什么FindAncestor结合在GridViewColumn不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建自己的GridViewColumn和具有约束力的一些伊苏斯。

I'm trying to create my own GridViewColumn and having some issus with binding.

有人能向我解释为什么下面的头结合确实工作

Can someone explain to me why the following Header-binding does work

<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>

而在这里失败了呢?

while it fails here?

<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继承的属性。

Sprache is a Property of my TranslateGridViewColumn which inherits from GridViewColumn.

推荐答案

几分钟张贴的问题后,我发现我的答案在此<一个href=\"http://stackoverflow.com/questions/4813237/how-to-use-relative-binding-mode-findancestor\">thread.
答案基本上是最高审计机关的GridViewColumn不会被添加到可视树,所以使用这种可视化树的绑定(例如FindAncestor)着的工作。

A few minutes after posting the question, I found my answer in this thread. The answer basically sais the GridViewColumn wont be added to the visual tree, so bindings which uses this visual tree (e.g. FindAncestor) cant work.

所以我subsribed到我结合(例如GridViewColumnHeader)元素的加载事件,并没有在绑定code-背后:

So I subsribed to the Loaded-events of the elements which I bind to (e.g. GridViewColumnHeader) and did the binding in Code-behind:

BindingOperations.SetBinding(sender as GridViewColumnHeader, GridViewColumnHeader.ContentProperty, new Binding("Sprache") { Source = this, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay });

这篇关于为什么FindAncestor结合在GridViewColumn不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆