If you want to get the MediaElement.Source
property from the button's Content
property, you can simply bind to it:
<MediaElement Source="{Binding Path=Content, RelativeSource={RelativeSource AncestorType=Button}}"
Stretch="Fill"/>
Question
I have a problem with Button
control. I've made Button
in Shape
of circle and MediaElement
inside it. Thats's my code:
<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>
My problem is that I cant bind MediaElement
Source from main XAML
:
<Button Template="{DynamicResource Templ}" Content="D:\dykta.avi"/>
Is there any way to make it work?
Solution
If you want to get the MediaElement.Source
property from the button's Content
property, you can simply bind to it:
<MediaElement Source="{Binding Path=Content, RelativeSource={RelativeSource AncestorType=Button}}"
Stretch="Fill"/>