When changing anchor on transition

I have a slider associated with the volume property of the MediaElement. This works if marked like this:

<UserControl
    x:Class="GenTest.VideoElement"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:GenTest"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="600">
    <UserControl.Resources>
        <Style x:Name="transportStyle"  TargetType="Button">
            <Setter Property="Height" Value="40" />
            <Setter Property="Width" Value="75" />
            <Setter Property="FontSize" Value="11" />
        </Style>
        <Style x:Name="atransportStyle"  TargetType="AppBarButton">
            <Setter Property="IsCompact" Value="true" />
            <Setter Property="FontSize" Value="11" />
        </Style>
    </UserControl.Resources>
    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="100"/>
        </Grid.RowDefinitions>

        <ContentControl x:Name="videoContainer" 
                            KeyUp="VideoContainer_KeyUp" 
                            HorizontalContentAlignment="Center" 
                            VerticalContentAlignment="Center" 
                            Height="400" Grid.Row="0" >
            <MediaElement Name="videoMediaElement"
                              MediaOpened="videoElement_MediaOpened" 
                              MediaEnded="videoMediaElement_MediaEnded" 
                              MediaFailed="videoMediaElement_MediaFailed"
                              CurrentStateChanged="videoMediaElement_CurrentStateChanged"
                              AutoPlay="False" />
        </ContentControl>
        <!-- Transport Controls -->
        <StackPanel Name="TransportControlsPanel" 
                    HorizontalAlignment="Center" 
                    Grid.Row="1" >
            <Slider Name="timelineSlider" Margin="0,0" Width="500" Height="37"/>
            <StackPanel Orientation="Horizontal">
                <AppBarButton x:Name="btnPlay" Icon="Play" Click="btnPlay_Click" Style="{StaticResource atransportStyle}" Label="Play"/>
                <AppBarButton x:Name="btnStop" Icon="Stop" Click="btnStop_Click" Style="{StaticResource atransportStyle}"/>
                <AppBarButton x:Name="btnReverse" Icon="Previous" Click="btnReverse_Click" Style="{StaticResource atransportStyle}"/>
                <AppBarButton x:Name="btnForward" Icon="Next" Click="btnForward_Click" Style="{StaticResource atransportStyle}"/>


                 <Button Name="btnFullScreenToggle" Click="btnFullScreenToggle_Click" 
                        Style="{StaticResource transportStyle}" Content="Full" />
                <ComboBox Name="cbAudioTracks"
                          SelectionChanged="cbAudioTracks_SelectionChanged" 
                          Width="75" />
                <AppBarButton x:Name="btnTest" Icon="Other" Style="{StaticResource atransportStyle}">
                    <AppBarButton.Flyout>
                        <Flyout>
                            <StackPanel Orientation="Vertical">

                            </StackPanel>
                        </Flyout>
                    </AppBarButton.Flyout>
                </AppBarButton>
                <Slider Minimum="0" Maximum="1"  StepFrequency="0.1" Height="100" Value="{Binding Mode=TwoWay, 
                    ElementName=videoMediaElement, Path=Volume}" Orientation="Vertical"/>
             </StackPanel>
        </StackPanel>
    </Grid>
</UserControl>

      

But when I put the slider in Fluight, the binding doesn't work anymore.

<AppBarButton x:Name="btnTest" Icon="Other" Style="{StaticResource atransportStyle}">
                    <AppBarButton.Flyout>
                        <Flyout>
                            <StackPanel Orientation="Vertical">
                                <Slider Minimum="0" Maximum="1"  StepFrequency="0.1" Height="100" Value="{Binding Mode=TwoWay, 
                    ElementName=videoMediaElement, Path=Volume}" Orientation="Vertical"/>
                            </StackPanel>
                        </Flyout>
                    </AppBarButton.Flyout>
                </AppBarButton>

      

There are no errors and I cannot make the binding because the TraceListeners have been removed from WinRt. I tried:

public App()
{
    this.InitializeComponent();
    this.Suspending += OnSuspending;
    this.UnhandledException += App_UnhandledException;
    DebugSettings.BindingFailed += OnDebugSettingsOnBindingFailed;
}

private void OnDebugSettingsOnBindingFailed(object sender, BindingFailedEventArgs args)
{
    new MessageDialog(args.Message).ShowAsync();
}

      

But no errors are thrown and there is nothing in the output window. In design mode using Windows properties, if I change the volume value for the videoMediaElement, the value of the Slider property changes, but I cannot update the value of the slider, it is read-only.

I can get it to work inside the popup if I use the code:

private void RangeBase_OnValueChanged(object sender, RangeBaseValueChangedEventArgs e)
    {
        var slider = sender as Slider;
        videoMediaElement.Volume = slider.Value; 
    }

      

but why bother with bindings at all?

+3


source to share


1 answer


I've had errors like this a few times now, I think Flyouts are handled separately where Bindings cannot look for ElementName.

I suggest you do it with a ViewModel instead of cross-linking in the page



Slider.Value [TwoWay-Bind] → ViewModel.Volume

ViewModel.Volume → videoMediaElement.Volume

+1


source







All Articles