Skip to content

Commit 2339c1b

Browse files
authored
Merge pull request #840 from unoplatform/dev/erli/828-chatui
chore: Update ChatUI to Uno.Sdk 5.4
2 parents a41990a + 5915758 commit 2339c1b

File tree

15 files changed

+344
-396
lines changed

15 files changed

+344
-396
lines changed

UI/ChatUI/src/ChatUI/App.xaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
<Application
2-
x:Class="ChatUI.App"
3-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
1+
<Application x:Class="ChatUI.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
54

65
<Application.Resources>
76
<ResourceDictionary>

UI/ChatUI/src/ChatUI/App.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System;
2-
using Microsoft.Extensions.Logging;
31
using Uno.Resizetizer;
42

53
namespace ChatUI;
Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,39 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using System.Windows.Input;
7-
using Microsoft.UI.Xaml;
8-
using Microsoft.UI.Xaml.Controls;
91
using Windows.System;
102

113
namespace ChatUI.Behaviors;
124

135
public class CommandOnKeyPressBehavior
146
{
15-
public static ICommand GetTextBoxCommand(DependencyObject dependencyObject)
16-
{
17-
return (ICommand)dependencyObject.GetValue(TextBoxCommandProperty);
18-
}
7+
public static ICommand GetTextBoxCommand(DependencyObject dependencyObject)
8+
{
9+
return (ICommand)dependencyObject.GetValue(TextBoxCommandProperty);
10+
}
1911

20-
public static void SetTextBoxCommand(DependencyObject dependencyObject, ICommand value)
21-
{
22-
dependencyObject.SetValue(TextBoxCommandProperty, value);
23-
}
12+
public static void SetTextBoxCommand(DependencyObject dependencyObject, ICommand value)
13+
{
14+
dependencyObject.SetValue(TextBoxCommandProperty, value);
15+
}
2416

25-
public static readonly DependencyProperty TextBoxCommandProperty =
26-
DependencyProperty.RegisterAttached("TextBoxCommand", typeof(ICommand), typeof(CommandOnKeyPressBehavior), new PropertyMetadata(default(ICommand), OnTextBoxCommandChanged));
27-
28-
private static void OnTextBoxCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
29-
{
30-
if(d is TextBox textBox)
31-
{
32-
textBox.KeyDown -= TextBox_KeyDown;
17+
public static readonly DependencyProperty TextBoxCommandProperty =
18+
DependencyProperty.RegisterAttached("TextBoxCommand", typeof(ICommand), typeof(CommandOnKeyPressBehavior), new PropertyMetadata(default(ICommand), OnTextBoxCommandChanged));
19+
20+
private static void OnTextBoxCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
21+
{
22+
if(d is TextBox textBox)
23+
{
24+
textBox.KeyDown -= TextBox_KeyDown;
3325

34-
textBox.KeyDown += TextBox_KeyDown;
35-
}
36-
}
26+
textBox.KeyDown += TextBox_KeyDown;
27+
}
28+
}
3729

38-
private static void TextBox_KeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
39-
{
40-
if (e.Key == VirtualKey.Enter)
41-
{
42-
var textBox = sender as TextBox;
43-
var command = GetTextBoxCommand(textBox);
44-
command.Execute(null);
45-
}
46-
}
30+
private static void TextBox_KeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
31+
{
32+
if (e.Key == VirtualKey.Enter)
33+
{
34+
var textBox = sender as TextBox;
35+
var command = GetTextBoxCommand(textBox);
36+
command.Execute(null);
37+
}
38+
}
4739
}
Lines changed: 97 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,121 @@
1-
using Microsoft.UI.Xaml;
2-
using Microsoft.UI.Xaml.Controls;
31
using Microsoft.UI.Xaml.Input;
4-
using Microsoft.UI.Xaml.Media;
52
using Windows.System;
63

74
namespace ChatUI.Behaviors;
85

96
public static class ReversedPointerWheel
107
{
11-
public static readonly DependencyProperty IsEnabledProperty = DependencyProperty.RegisterAttached(
12-
"IsEnabled",
13-
typeof(bool),
14-
typeof(ReversedPointerWheel),
15-
new PropertyMetadata(default(bool), OnIsEnabledChanged));
8+
public static readonly DependencyProperty IsEnabledProperty = DependencyProperty.RegisterAttached(
9+
"IsEnabled",
10+
typeof(bool),
11+
typeof(ReversedPointerWheel),
12+
new PropertyMetadata(default(bool), OnIsEnabledChanged));
1613

17-
public static bool GetIsEnabled(FrameworkElement element)
18-
=> (bool)element.GetValue(IsEnabledProperty);
14+
public static bool GetIsEnabled(FrameworkElement element)
15+
=> (bool)element.GetValue(IsEnabledProperty);
1916

20-
public static void SetIsEnabled(FrameworkElement element, bool value)
21-
=> element.SetValue(IsEnabledProperty, value);
17+
public static void SetIsEnabled(FrameworkElement element, bool value)
18+
=> element.SetValue(IsEnabledProperty, value);
2219

23-
private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
24-
{
25-
if (d is ScrollContentPresenter scp)
26-
{
20+
private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
21+
{
22+
if (d is ScrollContentPresenter scp)
23+
{
2724
#if HAS_UNO
28-
// We do have native support for reversed PointerWheel in Uno.
29-
Uno.UI.Xaml.Controls.ScrollContentPresenter.SetIsPointerWheelReversed(scp, (bool)e.NewValue);
25+
// We do have native support for reversed PointerWheel in Uno.
26+
Uno.UI.Xaml.Controls.ScrollContentPresenter.SetIsPointerWheelReversed(scp, (bool)e.NewValue);
3027
#else
31-
scp.PointerWheelChanged -= OnWheelChanged;
32-
if (e.NewValue is true)
33-
{
34-
scp.PointerWheelChanged += OnWheelChanged;
35-
}
28+
scp.PointerWheelChanged -= OnWheelChanged;
29+
if (e.NewValue is true)
30+
{
31+
scp.PointerWheelChanged += OnWheelChanged;
32+
}
3633
#endif
37-
}
38-
else if (d is FrameworkElement sv)
39-
{
40-
sv.Loaded -= PropagateValueToScp;
41-
if (e.NewValue != DependencyProperty.UnsetValue)
42-
{
43-
sv.Loaded += PropagateValueToScp;
44-
PropagateValueToScp(sv, null);
45-
}
34+
}
35+
else if (d is FrameworkElement sv)
36+
{
37+
sv.Loaded -= PropagateValueToScp;
38+
if (e.NewValue != DependencyProperty.UnsetValue)
39+
{
40+
sv.Loaded += PropagateValueToScp;
41+
PropagateValueToScp(sv, null);
42+
}
4643

47-
static void PropagateValueToScp(object sender, RoutedEventArgs? _)
48-
{
49-
if (sender is FrameworkElement sv && TryFindFirstChild(sv, 10, out ScrollContentPresenter scp))
50-
{
51-
SetIsEnabled(scp, GetIsEnabled(sv));
52-
}
53-
}
54-
}
55-
}
44+
static void PropagateValueToScp(object sender, RoutedEventArgs? _)
45+
{
46+
if (sender is FrameworkElement sv && TryFindFirstChild(sv, 10, out ScrollContentPresenter scp))
47+
{
48+
SetIsEnabled(scp, GetIsEnabled(sv));
49+
}
50+
}
51+
}
52+
}
5653

57-
private static void OnWheelChanged(object sender, PointerRoutedEventArgs e)
58-
{
59-
if (sender is not ScrollContentPresenter { ScrollOwner: ScrollViewer sv } scp || !GetIsEnabled(scp))
60-
{
61-
if (sender is FrameworkElement fe)
62-
{
63-
fe.PointerWheelChanged -= OnWheelChanged;
64-
}
54+
private static void OnWheelChanged(object sender, PointerRoutedEventArgs e)
55+
{
56+
if (sender is not ScrollContentPresenter { ScrollOwner: ScrollViewer sv } scp || !GetIsEnabled(scp))
57+
{
58+
if (sender is FrameworkElement fe)
59+
{
60+
fe.PointerWheelChanged -= OnWheelChanged;
61+
}
6562

66-
return;
67-
}
63+
return;
64+
}
6865

69-
var properties = e.GetCurrentPoint(null).Properties;
70-
if (e.KeyModifiers == VirtualKeyModifiers.Control)
71-
{
72-
// Zoom, do nothing.
73-
}
74-
else if (!scp.CanVerticallyScroll || properties.IsHorizontalMouseWheel || e.KeyModifiers == VirtualKeyModifiers.Shift)
75-
{
76-
if (scp.CanHorizontallyScroll)
77-
{
78-
sv.ChangeView(
79-
horizontalOffset: sv.HorizontalOffset + properties.MouseWheelDelta,
80-
verticalOffset: null,
81-
zoomFactor: null,
82-
disableAnimation: false);
66+
var properties = e.GetCurrentPoint(null).Properties;
67+
if (e.KeyModifiers == VirtualKeyModifiers.Control)
68+
{
69+
// Zoom, do nothing.
70+
}
71+
else if (!scp.CanVerticallyScroll || properties.IsHorizontalMouseWheel || e.KeyModifiers == VirtualKeyModifiers.Shift)
72+
{
73+
if (scp.CanHorizontallyScroll)
74+
{
75+
sv.ChangeView(
76+
horizontalOffset: sv.HorizontalOffset + properties.MouseWheelDelta,
77+
verticalOffset: null,
78+
zoomFactor: null,
79+
disableAnimation: false);
8380

84-
e.Handled = true;
85-
}
86-
}
87-
else
88-
{
89-
sv.ChangeView(
90-
horizontalOffset: null,
91-
verticalOffset: sv.VerticalOffset + properties.MouseWheelDelta,
92-
zoomFactor: null,
93-
disableAnimation: false);
81+
e.Handled = true;
82+
}
83+
}
84+
else
85+
{
86+
sv.ChangeView(
87+
horizontalOffset: null,
88+
verticalOffset: sv.VerticalOffset + properties.MouseWheelDelta,
89+
zoomFactor: null,
90+
disableAnimation: false);
9491

95-
e.Handled = true;
96-
}
97-
}
92+
e.Handled = true;
93+
}
94+
}
9895

99-
private static bool TryFindFirstChild<T>(DependencyObject element, uint limit, /*[NotNullWhen(true)]*/ out T result)
100-
{
101-
// Finds the first child of type T in the visual tree of element.
102-
// This is a workaround for the fact that ScrollViewer doesn't expose its ScrollContentPresenter.
96+
private static bool TryFindFirstChild<T>(DependencyObject element, uint limit, /*[NotNullWhen(true)]*/ out T result)
97+
{
98+
// Finds the first child of type T in the visual tree of element.
99+
// This is a workaround for the fact that ScrollViewer doesn't expose its ScrollContentPresenter.
103100

104-
if (element is T t)
105-
{
106-
result = t;
107-
return true;
108-
}
101+
if (element is T t)
102+
{
103+
result = t;
104+
return true;
105+
}
109106

110-
if (limit is not 0)
111-
{
112-
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
113-
{
114-
if (TryFindFirstChild(VisualTreeHelper.GetChild(element, i), limit - 1, out result))
115-
{
116-
return true;
117-
}
118-
}
119-
}
107+
if (limit is not 0)
108+
{
109+
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
110+
{
111+
if (TryFindFirstChild(VisualTreeHelper.GetChild(element, i), limit - 1, out result))
112+
{
113+
return true;
114+
}
115+
}
116+
}
120117

121-
result = default;
122-
return false;
123-
}
118+
result = default;
119+
return false;
120+
}
124121
}

UI/ChatUI/src/ChatUI/ChatUI.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@
1818
<Description>ChatUI powered by Uno Platform.</Description>
1919
<!--
2020
If you encounter this error message:
21-
2221
error NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll.
2322
Please update to a newer .NET SDK in order to reference this assembly.
24-
2523
This means that the two packages below must be aligned with the "build" version number of
2624
the "Microsoft.Windows.SDK.BuildTools" package above, and the "revision" version number
2725
must be the highest found in https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref.
2826
-->
29-
<!-- <WindowsSdkPackageVersion>10.0.22621.28</WindowsSdkPackageVersion> -->
3027

31-
<!--
28+
<!-- Uno Platform 5.4 has been updated to use WinAppSDK 1.6, which necessitates a temporary version adjustment until newer versions of .NET 8 SDKs are released. -->
29+
<!-- Comment this WindowsSdkPackageVersion line again once .NET SDK version 8.0.403 or later is available. -->
30+
<!-- For more details, refer to: https://aka.platform.uno/migrate-from-previous#uno-platform-54 -->
31+
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
32+
33+
<!--
3234
UnoFeatures let's you quickly add and manage implicit package references based on the features you want to use.
3335
https://aka.platform.uno/singleproject-features
3436
-->
Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using System.Windows.Input;
7-
81
namespace ChatUI.Commands;
92

103
public class RelayCommand : ICommand
114
{
12-
private Action<string> _execute;
5+
private Action<string> _execute;
136

14-
public RelayCommand(Action<string> execute)
15-
{
16-
_execute = execute;
17-
}
7+
public RelayCommand(Action<string> execute)
8+
{
9+
_execute = execute;
10+
}
1811

19-
public event EventHandler CanExecuteChanged;
12+
public event EventHandler CanExecuteChanged;
2013

21-
public bool CanExecute(object parameter)
22-
{
23-
return true;
24-
}
14+
public bool CanExecute(object parameter)
15+
{
16+
return true;
17+
}
2518

26-
public void Execute(object parameter)
27-
{
28-
_execute((string)parameter);
29-
}
30-
}
19+
public void Execute(object parameter)
20+
{
21+
_execute((string)parameter);
22+
}
23+
}

0 commit comments

Comments
 (0)