Hello. Due to circumstances, I had to implement MediaElement on the App.xaml page.

<Application.Resources> <MediaElement x:Key="GlobalPlayer" AudioCategory="BackgroundCapableMedia" AutoPlay="True" Visibility="Collapsed"/> </Application.Resources> 

From MainPage.xaml.cs, I can easily access it. But there is also the ProgressBar, which is specified in MainPage.xaml

  <ProgressBar Visibility="Collapsed" Height="5" x:Name="PlayingProgressBar" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Maximum="{Binding Path=NaturalDuration.TimeSpan.TotalSeconds, Mode=TwoWay, ElementName=App.Player}" Value="{Binding Path=Position.TotalSeconds, Mode=TwoWay, ElementName=Player}" Grid.Row="3" Margin="0,0,60,0" ShowPaused="True" BorderBrush="{ThemeResource MediaButtonBackgroundThemeBrush}" Foreground="{ThemeResource MediaButtonPointerOverBackgroundThemeBrush}" AutomationProperties.AccessibilityView="Control"/> 

How to bind data between pages from this MediaElement for ProgressBar?

Update

The player itself.

  <Application.Resources> <MediaElement x:Key="GlobalPlayer" Name="GlobalPlayer" AudioCategory="BackgroundCapableMedia" AutoPlay="True" Visibility="Collapsed" /> </Application.Resources> 

 Привязка к нему из любой страницы. <ProgressBar x:Name="PlayingProgressBar" Height="10" VerticalAlignment="Center" HorizontalAlignment="Stretch" ShowPaused="True" BorderBrush="{ThemeResource MediaButtonBackgroundThemeBrush}" Maximum="{Binding NaturalDuration.TimeSpan.TotalSeconds, Mode=OneWay, Source={StaticResource GlobalPlayer}}" Value="{Binding Position.TotalSeconds, Mode=OneWay, Source={StaticResource GlobalPlayer}}"/> 

  • You are doing wrong. UI elements do not need to be put into resources. Tell us what your real problem is. - VladD
  • Associate the “global” media element that is specified in the App.xaml with the progress bar located on the MainPage.xaml page. - Morgomirius
  • one
    No, no, stand. You cannot make a “global” UI element, since UI elements cannot be shared. The question is what problem you are trying to solve by putting MediaElement into resources. This problem needs to be solved differently. - VladD pm

0