2
我想創建我自己的GridViewColumn,並有一些綁定issus。爲什麼FindAncestor綁定在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繼承的財產。
你得到任何'BindingExpression'錯誤在你的調試輸出窗口? – DHN 2013-03-14 09:19:32
爲什麼你不使用第一種形式,如果它工作? – nemesv 2013-03-14 09:21:13
@DHN是的,它是「無法找到與參考綁定的源」RelativeSource FindAncestor,AncestorType ='interneProzesse_UebersetzungstoolNS.TranslateGridViewColumn',AncestorLevel ='1''。但是我想知道它爲什麼找不到,因爲'TranslateGridViewColumn'確實是一個祖先。 – 2013-03-14 09:24:49