使用FindAncestor查找方式绑定且不需要使用datacontext

<UserControl x:Class="QuJiao.AnimationVideoPlayer"
             xmlns:local="clr-namespace:QuJiao">

<TextBlock 
	Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Stretch"
	x:Name="TextBlock1"
	Foreground="#999999"
	FontFamily="微软雅黑"
	FontSize="20"
	Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorLevel=1,AncestorType=local:AnimationVideoPlayer},Path=VolumeText}"
/>

其中[local:AnimationVideoPlayer]即为在此类中查找绑定目标[VolumeText],AncestorLevel=1为搜索第一层

猜你喜欢

转载自blog.csdn.net/FireGhost57/article/details/87122194
今日推荐