From ad8c82e3ed9a5f87209a1a22ac5770f1663e2837 Mon Sep 17 00:00:00 2001 From: Insomniachi Date: Mon, 11 Mar 2024 11:48:03 +0530 Subject: [PATCH] rever winappsdk update --- Totoro.WinUI/Behaviors/SelectorBarBehavior.cs | 75 ------------------- Totoro.WinUI/Totoro.WinUI.csproj | 12 +-- .../UserControls/PivotNavigation.xaml | 29 +++++-- 3 files changed, 28 insertions(+), 88 deletions(-) delete mode 100644 Totoro.WinUI/Behaviors/SelectorBarBehavior.cs diff --git a/Totoro.WinUI/Behaviors/SelectorBarBehavior.cs b/Totoro.WinUI/Behaviors/SelectorBarBehavior.cs deleted file mode 100644 index 967052e..0000000 --- a/Totoro.WinUI/Behaviors/SelectorBarBehavior.cs +++ /dev/null @@ -1,75 +0,0 @@ -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; -using Microsoft.Xaml.Interactivity; -using Totoro.Core.ViewModels; -using ReactiveMarbles.ObservableEvents; - -namespace Totoro.WinUI.Behaviors; - -public class SelectorBarBehavior : Behavior -{ - public IEnumerable ItemSource - { - get { return (IEnumerable)GetValue(ItemSourceProperty); } - set { SetValue(ItemSourceProperty, value); } - } - - public PivotItemModel SelectedItem - { - get { return (PivotItemModel)GetValue(SelectedItemProperty); } - set { SetValue(SelectedItemProperty, value); } - } - - public static readonly DependencyProperty SelectedItemProperty = - DependencyProperty.Register("SelectedItem", typeof(PivotItemModel), typeof(SelectorBarBehavior), new PropertyMetadata(null)); - - public static readonly DependencyProperty ItemSourceProperty = - DependencyProperty.Register("ItemSource", typeof(IEnumerable), typeof(SelectorBarBehavior), new PropertyMetadata(Enumerable.Empty())); - - - protected override void OnAttached() - { - this.WhenAnyValue(x => x.ItemSource) - .Where(x => x is not null && x.Any() && AssociatedObject is not null) - .ObserveOn(RxApp.MainThreadScheduler) - .Subscribe(values => - { - AssociatedObject.Items.Clear(); - foreach (var item in values.Where(x => x.Visible)) - { - AssociatedObject.Items.Add(new SelectorBarItem - { - Text = item.Header, - FontSize = 20 - }); - } - - if(SelectedItem is null) - { - AssociatedObject.SelectedItem = AssociatedObject.Items.FirstOrDefault(); - } - }); - - this.WhenAnyValue(x => x.SelectedItem) - .WhereNotNull() - .Where(_ => AssociatedObject is not null) - .ObserveOn(RxApp.MainThreadScheduler) - .Subscribe(item => - { - if (AssociatedObject.Items.FirstOrDefault(x => x.Text == item.Header) is not { } uiItem) - { - return; - } - - AssociatedObject.SelectedItem = uiItem; - }); - - AssociatedObject - .Events() - .SelectionChanged - .Select(x => x.sender.SelectedItem?.Text) - .Where(text => !string.IsNullOrEmpty(text)) - .Subscribe(header => SelectedItem = ItemSource.FirstOrDefault(x => x.Header == header)); - - } -} diff --git a/Totoro.WinUI/Totoro.WinUI.csproj b/Totoro.WinUI/Totoro.WinUI.csproj index c7f6dd3..26850d2 100644 --- a/Totoro.WinUI/Totoro.WinUI.csproj +++ b/Totoro.WinUI/Totoro.WinUI.csproj @@ -39,22 +39,22 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + - + diff --git a/Totoro.WinUI/UserControls/PivotNavigation.xaml b/Totoro.WinUI/UserControls/PivotNavigation.xaml index be4e89c..f41b92e 100644 --- a/Totoro.WinUI/UserControls/PivotNavigation.xaml +++ b/Totoro.WinUI/UserControls/PivotNavigation.xaml @@ -2,25 +2,40 @@ x:Class="Totoro.WinUI.UserControls.PivotNavigation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" - xmlns:b="using:Totoro.WinUI.Behaviors" + xmlns:ctk="using:CommunityToolkit.WinUI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Margin="0,30" mc:Ignorable="d"> + + + + + + + + - - - - - + + + + + +