use*_*959 0 c# data-binding wpf xaml mvvm
我要绑定ParentSidebar的SelectIngredient到根Sidebar以下XAML.DataContext的Sidebar,所以我不能用它设置一些数据在后台代码.我想在不使用的情况下实现这一点ElementName.可能吗?
<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>
Run Code Online (Sandbox Code Playgroud)
编辑:
在Visual Tree中,Sidebar是一个兄弟姐妹SelectIngredient.所以它只是逻辑上的父母,但实际上并非如此.
<Sidebar.Resources>
<SelectIngredient x:Key="selectIngredient" x:Name="selectIngredient"
ParentSideBar={Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=SideBar, AncestorLevel=1}}>
</SelectIngredient>
</Sidebar.Resources>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42 次 |
| 最近记录: |