問題是RelativeSource
在以下情況下不起作用。我使用Silverlight 5RelativeSource和Popup
//From MainPage.xaml
<Grid x:Name="LayoutRoot" Background="White" Height="100" Width="200">
<Popup IsOpen="True">
<TextBlock Text="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType=Grid}}" />
</Popup>
</Grid>
//From MainPage.xaml.cs
public MainPage()
{
InitializeComponent();
DataContext = "ololo";
}
如果我設置綁定一個斷點,我會得到錯誤:如果我使用ElementName=LayoutRoot
代替RelativeSource
System.Exception: BindingExpression_CannotFindAncestor.
,一切都會好的。
爲什麼相對源綁定不起作用?
好的。彈出控制很明顯。有沒有在ComboBoxItemTemplate中使用相對源的方法? – 2013-02-18 17:22:47