@@ -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
0 commit comments