我想在下面的XAML中將ParentSidebar
的SelectIngredient
綁定到根Sidebar
。 DataContext
的Sidebar
被設置爲代碼隱藏的一些數據,所以我不能使用它。我想在不使用ElementName
的情況下實現此目的。可能嗎?如何從資源部分內部綁定到數據綁定的UserControl?
<Sidebar x:Class="MyApplication.Sidebar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Sidebar.Resources>
<SelectIngredient x:Key="selectIngredient" x:Name="selectIngredient"
ParentSidebar="{Binding ???}">
</SelectIngredient>
</Sidebar.Resources>
</Sidebar>
編輯:
在Visual樹,Sidebar
是SelectIngredient
兄弟。所以這只是一個邏輯上的父母,但實際上並非如此。
問題解決了嗎? –