我有我的UserControl
內兩個控件,我綁定到使用元素完全相同的對象綁定:WPF元素綁定
AllowNext="{Binding ElementName=MainGrid, Path=DataContext.CanContinue}"
在第一控制它工作正常,但在第二,我得到一個結合異常:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=MainGrid'. BindingExpression:Path=DataContext.CanContinue; DataItem=null; target element is 'WizardPage' (Name='DeductionPage'); target property is 'AllowNext' (type 'Boolean')
我也使用RelativeSource
在第二對照結合的嘗試:
AllowNext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid}}, Path=DataContext.CanContinue}"
但這也給我一個錯誤。
有誰知道這可能是什麼?
-
下面是簡單的控制:
<Grid Name="MainGrid">
<w:Wizard Name="MyWizard" w:Designer.PageIndex="1" DataContext="{Binding ElementName=MainGrid, Path=DataContext.Policy}" >
<w:WizardPage Header="Main Member" MaxHeight="600" AllowNext="{Binding ElementName=MainGrid, Path=DataContext.CanContinue}" Name="MainPage">
</w:WizardPage>
<w:WizardPage Name="DeductionPage" Header="Policy Details" AllowBack="False" AllowNext="{Binding ElementName=MainGrid, Path=DataContext.CanContinue}">
</w:WizardPage>
</w:Wizard>
</Grid>
現在,正如我所說,結合的MainPage罰款,而DeductionPage完全不綁定並獲取提供的錯誤。 MainGrid的DataContext的是從代碼中設置的背後:
public void SetDataContext(object o)
{
MainGrid.DataContext = o;
}
請問您可以發佈您的UserControl的源?我的第一個猜測是,這可能是一個DataContext問題? – Dutts 2013-02-18 08:16:24
我更新了我的問題! – 2013-02-18 08:37:09