Das Problem ist, dass RelativeSource
im folgenden Fall nicht funktioniert. Ich benutze Silverlight 5.RelativeSource und 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";
}
Wenn ich einen Haltepunkt auf der Bindung eingestellt, ich Fehler bekommen:
System.Exception: BindingExpression_CannotFindAncestor.
Wenn ich ElementName=LayoutRoot
anstelle von RelativeSource
, wird alles in Ordnung sein.
Warum funktioniert die relative Quellenbindung nicht?
Ok. Das ist für die Popup-Kontrolle klar. Gibt es eine Möglichkeit, relative Quelle in ComboBoxItemTemplate zu verwenden? –