[英]Binding using a relative source and dependency property - MVVM
有人可以解釋我與MVVM綁定時的Relativesource-祖先功能。 基本上,依賴屬性通過視圖模型綁定到具有上述概念的按鈕。 對樣本進行一些解釋會很棒。 或者一些鏈接也可以。
編輯1:
<Button Name="button1" Content ="Edit" Margin="0, 0, 5, 0" Style="{StaticResource button}"
Grid.Column="0" Visibility="{Binding cMode, Converter={StaticResource VisibilityConverter}, ConverterParameter={StaticResource invert}}"
Click="EditButton_Click"
IsEnabled="{Binding Path= Data.User.CanEdit, RelativeSource={RelativeSource FindAncestor, AncestorType=views:SCView, AncestorLevel=1}}"/>
CanEdit也是一個依賴屬性
它搜索Ancestors元素,直到它找到AncestorType的元素。 該元素將被視為Source。
在以下示例中,Button的寬度與Grid相同:
<Grid Width="100"> <!--Level=2-->
<Border> <!--Level=1-->
<Button Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Grid}}, Path=ActualWidth}"/>
</Border>
</Grid>
此外,您可以通過設置AncestorLevel來設置要搜索的級別。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.