Skip to content

Commit d48e9fc

Browse files
committed
chore: Adjustments
1 parent 01ada82 commit d48e9fc

File tree

3 files changed

+71
-61
lines changed

3 files changed

+71
-61
lines changed

src/Uno.UI/UI/Xaml/Controls/ContentDialog/ContentDialog.h.mux.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// MUX Reference ContentDialog_Partial.h, tag winui3/release/1.6-stable
22

33
using System;
4+
using System.Threading.Tasks;
45
using Microsoft.UI.Xaml.Controls.Primitives;
56
using Microsoft.UI.Xaml.Media;
67
using Microsoft.UI.Xaml.Media.Animation;
@@ -52,7 +53,9 @@ private enum FullMode
5253
/* Tracked references */
5354
private IAsyncOperation<ContentDialogResult> m_tpCurrentAsyncOperation;
5455
private Popup m_tpPopup;
56+
#pragma warning disable CS0649 // Field is never assigned to
5557
private Popup m_tpSmokeLayerPopup;
58+
#pragma warning restore CS0649
5659
private FrameworkElement m_tpSmokeLayer;
5760
private VisualStateGroup m_tpDialogShowingStates;
5861

src/Uno.UI/UI/Xaml/Controls/ContentDialog/ContentDialog.mux.cs

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ private void OnBackRequested(object sender, BackRequestedEventArgs e)
149149
}
150150
#endif
151151

152-
private void OnPropertyChanged2(DependencyPropertyChangedEventArgs args)
152+
internal override void OnPropertyChanged2(DependencyPropertyChangedEventArgs args)
153153
{
154+
base.OnPropertyChanged2(args);
155+
154156
// We only react to property changes if ContentDialog is currently visible
155157
if (m_tpCurrentAsyncOperation == null ||
156158
!m_hasPreparedContent ||
@@ -1015,39 +1017,34 @@ private void ProcessLayoutRootKey(bool isKeyDown, KeyRoutedEventArgs args)
10151017
{
10161018
var key = args.Key;
10171019

1018-
switch (key)
1020+
if (key == VirtualKey.Escape)
10191021
{
1020-
case VirtualKey.Escape:
1021-
{
1022-
var originalKey = args.OriginalKey;
1022+
var originalKey = args.OriginalKey;
10231023

1024-
if ((!isKeyDown && originalKey == VirtualKey.GamepadB) ||
1025-
(isKeyDown && originalKey == VirtualKey.Escape))
1026-
{
1027-
ExecuteCloseAction();
1028-
args.Handled = true;
1029-
}
1030-
break;
1024+
if ((!isKeyDown && originalKey == VirtualKey.GamepadB) ||
1025+
(isKeyDown && originalKey == VirtualKey.Escape))
1026+
{
1027+
ExecuteCloseAction();
1028+
args.Handled = true;
10311029
}
1032-
case VirtualKey.Enter:
1030+
}
1031+
else if (key == VirtualKey.Enter)
1032+
{
1033+
if (isKeyDown)
10331034
{
1034-
if (isKeyDown)
1035-
{
1036-
var defaultButton = GetDefaultButtonHelper();
1035+
var defaultButton = GetDefaultButtonHelper();
10371036

1038-
if (defaultButton is ButtonBase buttonBase && buttonBase.IsEnabled)
1037+
if (defaultButton is ButtonBase buttonBase && buttonBase.IsEnabled)
1038+
{
1039+
// TODO Uno: ProgrammaticClick is internal on ButtonBase
1040+
// buttonBase.ProgrammaticClick();
1041+
var peer = Microsoft.UI.Xaml.Automation.Peers.FrameworkElementAutomationPeer.FromElement(buttonBase);
1042+
if (peer is Microsoft.UI.Xaml.Automation.Peers.ButtonAutomationPeer buttonPeer)
10391043
{
1040-
// TODO Uno: ProgrammaticClick is internal on ButtonBase
1041-
// buttonBase.ProgrammaticClick();
1042-
var peer = Microsoft.UI.Xaml.Automation.Peers.FrameworkElementAutomationPeer.FromElement(buttonBase);
1043-
if (peer is Microsoft.UI.Xaml.Automation.Peers.ButtonAutomationPeer buttonPeer)
1044-
{
1045-
buttonPeer.Invoke();
1046-
}
1047-
args.Handled = true;
1044+
buttonPeer.Invoke();
10481045
}
1046+
args.Handled = true;
10491047
}
1050-
break;
10511048
}
10521049
}
10531050
}
@@ -1423,34 +1420,47 @@ private void SetButtonPropertiesFromCommand(ContentDialogButton buttonType, ICom
14231420

14241421
if (button != null)
14251422
{
1426-
// TODO Uno: XamlUICommand integration (CommandingHelpers)
1427-
// When the command implements IXamlUICommand, binding to Label, KeyboardAccelerators,
1428-
// AccessKey, and Description should be done here.
1429-
// Original C++:
1430-
// if (oldCommand)
1431-
// {
1432-
// auto oldCommandAsUICommand = oldCommand.AsOrNull<IXamlUICommand>();
1433-
// if (oldCommandAsUICommand)
1434-
// {
1435-
// CommandingHelpers::ClearBindingIfSet(oldCommandAsUICommand, this, textPropertyIndex);
1436-
// CommandingHelpers::ClearBindingIfSet(oldCommandAsUICommand, button, KnownPropertyIndex::UIElement_KeyboardAccelerators);
1437-
// CommandingHelpers::ClearBindingIfSet(oldCommandAsUICommand, button, KnownPropertyIndex::UIElement_AccessKey);
1438-
// CommandingHelpers::ClearBindingIfSet(oldCommandAsUICommand, button, KnownPropertyIndex::AutomationProperties_HelpText);
1439-
// CommandingHelpers::ClearBindingIfSet(oldCommandAsUICommand, button, KnownPropertyIndex::ToolTipService_ToolTip);
1440-
// }
1441-
// }
1442-
//
1443-
// if (newCommand)
1444-
// {
1445-
// auto newCommandAsUICommand = newCommand.AsOrNull<IXamlUICommand>();
1446-
// if (newCommandAsUICommand)
1447-
// {
1448-
// CommandingHelpers::BindToLabelPropertyIfUnset(newCommandAsUICommand, this, textPropertyIndex);
1449-
// CommandingHelpers::BindToKeyboardAcceleratorsIfUnset(newCommandAsUICommand, button);
1450-
// CommandingHelpers::BindToAccessKeyIfUnset(newCommandAsUICommand, button);
1451-
// CommandingHelpers::BindToDescriptionPropertiesIfUnset(newCommandAsUICommand, button);
1452-
// }
1453-
// }
1423+
DependencyProperty textProperty = buttonType switch
1424+
{
1425+
ContentDialogButton.Primary => PrimaryButtonTextProperty,
1426+
ContentDialogButton.Secondary => SecondaryButtonTextProperty,
1427+
ContentDialogButton.Close => CloseButtonTextProperty,
1428+
_ => null,
1429+
};
1430+
1431+
ICommand newCommand = buttonType switch
1432+
{
1433+
ContentDialogButton.Primary => PrimaryButtonCommand,
1434+
ContentDialogButton.Secondary => SecondaryButtonCommand,
1435+
ContentDialogButton.Close => CloseButtonCommand,
1436+
_ => null,
1437+
};
1438+
1439+
if (oldCommand != null)
1440+
{
1441+
if (textProperty != null)
1442+
{
1443+
CommandingHelpers.ClearBindingIfSet(oldCommand, this, textProperty);
1444+
}
1445+
CommandingHelpers.ClearBindingIfSet(oldCommand, button, UIElement.KeyboardAcceleratorsProperty);
1446+
CommandingHelpers.ClearBindingIfSet(oldCommand, button, UIElement.AccessKeyProperty);
1447+
CommandingHelpers.ClearBindingIfSet(oldCommand, button, Automation.AutomationProperties.HelpTextProperty);
1448+
CommandingHelpers.ClearBindingIfSet(oldCommand, button, ToolTipService.ToolTipProperty);
1449+
}
1450+
1451+
if (newCommand != null)
1452+
{
1453+
if (textProperty != null)
1454+
{
1455+
CommandingHelpers.BindToLabelPropertyIfUnset(newCommand, this, textProperty);
1456+
}
1457+
if (newCommand is Input.XamlUICommand uiCommand)
1458+
{
1459+
CommandingHelpers.BindToKeyboardAcceleratorsIfUnset(uiCommand, button);
1460+
CommandingHelpers.BindToAccessKeyIfUnset(uiCommand, button);
1461+
CommandingHelpers.BindToDescriptionPropertiesIfUnset(uiCommand, button);
1462+
}
1463+
}
14541464
}
14551465
}
14561466

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
using System;
1+
using Windows.Foundation;
22

33
namespace Microsoft.UI.Xaml.Controls
44
{
55
public partial class ContentDialogButtonClickDeferral
66
{
7-
private readonly Action _deferralAction;
7+
private readonly DeferralCompletedHandler _handler;
88

9-
internal ContentDialogButtonClickDeferral(Action deferralAction)
10-
{
11-
_deferralAction = deferralAction;
12-
}
9+
internal ContentDialogButtonClickDeferral(DeferralCompletedHandler handler) => _handler = handler;
1310

14-
public void Complete() => _deferralAction?.Invoke();
11+
public void Complete() => _handler?.Invoke();
1512
}
1613
}

0 commit comments

Comments
 (0)