我想在下面的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
兄弟。所以这只是一个逻辑上的父母,但实际上并非如此。
问题解决了吗? –