Fix region bug
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using System;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.Xaml.Interactivity;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.Xaml.Interactivity;
|
||||
using Windows.Media.Playback;
|
||||
|
||||
namespace Toolkit.UI.WinUI;
|
||||
|
||||
public class MediaPlayerBehavior :
|
||||
Behavior<MediaPlayerElement>
|
||||
{
|
||||
public static readonly DependencyProperty MediaPlayerProperty =
|
||||
DependencyProperty.Register(nameof(MediaPlayer),
|
||||
typeof(MediaPlayer), typeof(MediaPlayerBehavior),
|
||||
new PropertyMetadata(null, OnMediaPlayerPropertyChanged));
|
||||
|
||||
public MediaPlayer MediaPlayer
|
||||
{
|
||||
get => (MediaPlayer)GetValue(MediaPlayerProperty);
|
||||
set => SetValue(MediaPlayerProperty, value);
|
||||
}
|
||||
|
||||
private static void OnMediaPlayerPropertyChanged(DependencyObject dependencyObject,
|
||||
DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
if (dependencyObject is MediaPlayerBehavior behavior)
|
||||
{
|
||||
behavior.OnMediaPlayerPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMediaPlayerPropertyChanged() =>
|
||||
SetMediaPlayer();
|
||||
|
||||
private void SetMediaPlayer()
|
||||
{
|
||||
if (MediaPlayer is not null && AssociatedObject is not null)
|
||||
{
|
||||
AssociatedObject.SetMediaPlayer(MediaPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAttached()
|
||||
{
|
||||
base.OnAttached();
|
||||
SetMediaPlayer();
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,8 @@ public class NavigateAction :
|
||||
|
||||
public static readonly DependencyProperty ScopeProperty =
|
||||
DependencyProperty.Register(nameof(Scope),
|
||||
typeof(string), typeof(NavigateAction),
|
||||
new PropertyMetadata(null));
|
||||
typeof(NavigateScope), typeof(NavigateAction),
|
||||
new PropertyMetadata(NavigateScope.Default));
|
||||
|
||||
public static readonly DependencyProperty ParametersProperty =
|
||||
DependencyProperty.Register(nameof(Parameters),
|
||||
@@ -38,8 +38,6 @@ public class NavigateAction :
|
||||
|
||||
private ParameterCollection parameterCollection = [];
|
||||
|
||||
public event EventHandler? Navigated;
|
||||
|
||||
public object Region
|
||||
{
|
||||
get => GetValue(RegionProperty);
|
||||
@@ -55,9 +53,9 @@ public class NavigateAction :
|
||||
set => SetValue(RouteProperty, value);
|
||||
}
|
||||
|
||||
public string Scope
|
||||
public NavigateScope Scope
|
||||
{
|
||||
get => (string)GetValue(ScopeProperty);
|
||||
get => (NavigateScope)GetValue(ScopeProperty);
|
||||
set => SetValue(ScopeProperty, value);
|
||||
}
|
||||
|
||||
@@ -74,8 +72,8 @@ public class NavigateAction :
|
||||
ImmutableDictionary<string, object>? parameters = Parameters is { Count: > 0 } ? Parameters.ToImmutableDictionary(x => x.Key, x => x.Value) :
|
||||
ImmutableDictionary<string, object>.Empty;
|
||||
|
||||
observableViewModel.Messenger.Send(new NavigateEventArgs(Route, Region.Equals(this) ? content : Region, Scope ?? null,
|
||||
content.DataContext, Navigated, parameters));
|
||||
observableViewModel.Messenger.Send(new NavigateEventArgs(Route, Region.Equals(this) ? content : Region, Scope,
|
||||
content.DataContext, parameters));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user