从按钮内容(WPF)绑定MediaElement源

时间:2013-06-02 20:18:41

标签: wpf xaml templates button mediaelement

我遇到Button控制问题。我在Button圈内ShapeMediaElement圈内<Application.Resources> <ControlTemplate x:Key="Templ" TargetType="{x:Type Button}"> <Grid Margin="5"> <Ellipse Fill="#FF6DB4EF"/> <Ellipse Width="100" Height="100"> <Ellipse.Fill> <RadialGradientBrush> <GradientStop Offset="0" Color="#00000000"/> <GradientStop Offset="0.88" Color="#00000000"/> <GradientStop Offset="1" Color="#80000000"/> </RadialGradientBrush> </Ellipse.Fill> </Ellipse> <Ellipse Margin="10"> <Ellipse.Fill> <VisualBrush> <VisualBrush.Visual> <MediaElement Source="{???}" Stretch="Fill"/> </VisualBrush.Visual> </VisualBrush> </Ellipse.Fill> </Ellipse> </Grid> </ControlTemplate> </Application.Resources> 。那是我的代码:

MediaElement

我的问题是我无法绑定来自主XAML的{​​{1}}来源:

<Button Template="{DynamicResource Templ}" Content="D:\dykta.avi"/>

有没有办法让它发挥作用?

1 个答案:

答案 0 :(得分:1)

如果要从按钮的MediaElement.Source属性获取Content属性,只需绑定到它:

<MediaElement Source="{Binding Path=Content, RelativeSource={RelativeSource AncestorType=Button}}"
              Stretch="Fill"/>