From de784813403384678f88a8ad8a94501cc0d93dad Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Mon, 2 Mar 2020 09:57:30 +0100 Subject: [PATCH] feat: Added support for DropDownButton from MUX --- .../UITests.Shared/UITests.Shared.projitems | 7 + .../DropDownButton/DropDownButtonPage.xaml | 76 +++++++++++ .../DropDownButton/DropDownButtonPage.xaml.cs | 70 ++++++++++ .../DropDownButton.cs | 4 +- .../Controls/DropDownButton/DropDownButton.cs | 78 +++++++++++ .../DropDownButton/DropDownButton.xaml | 128 ++++++++++++++++++ 6 files changed, 361 insertions(+), 2 deletions(-) create mode 100644 src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/DropDownButton/DropDownButtonPage.xaml create mode 100644 src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/DropDownButton/DropDownButtonPage.xaml.cs create mode 100644 src/Uno.UI/UI/Xaml/Controls/DropDownButton/DropDownButton.cs create mode 100644 src/Uno.UI/UI/Xaml/Controls/DropDownButton/DropDownButton.xaml diff --git a/src/SamplesApp/UITests.Shared/UITests.Shared.projitems b/src/SamplesApp/UITests.Shared/UITests.Shared.projitems index 7c5206d7ee0d..66e4afcef902 100644 --- a/src/SamplesApp/UITests.Shared/UITests.Shared.projitems +++ b/src/SamplesApp/UITests.Shared/UITests.Shared.projitems @@ -637,6 +637,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -3422,6 +3426,9 @@ Control_IsEnabled_Inheritance.xaml + + DropDownButtonPage.xaml + DatePickerFlyout_Unloaded.xaml diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/DropDownButton/DropDownButtonPage.xaml b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/DropDownButton/DropDownButtonPage.xaml new file mode 100644 index 000000000000..218838408c1c --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/DropDownButton/DropDownButtonPage.xaml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Click count: + + Flyout opened: + + Flyout closed: + + + + + + + + diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/DropDownButton/DropDownButtonPage.xaml.cs b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/DropDownButton/DropDownButtonPage.xaml.cs new file mode 100644 index 000000000000..c90e6efca8a1 --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/DropDownButton/DropDownButtonPage.xaml.cs @@ -0,0 +1,70 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Markup; +using Windows.UI; +using System.Windows.Input; +using Uno.UI.Samples.Controls; + +namespace MUXControlsTestApp +{ + + [SampleControlInfo("DropDownButton", "MUX Page")] + public sealed partial class DropDownButtonPage + { + private int _clickCount = 0; + private int _flyoutOpenedCount = 0; + private int _flyoutClosedCount = 0; + + private Flyout _flyout; + + public DropDownButtonPage() + { + this.InitializeComponent(); + + _flyout = new Flyout(); + _flyout.Placement = FlyoutPlacementMode.Bottom; + TextBlock textBlock = new TextBlock(); + textBlock.Text = "New Flyout"; + _flyout.Content = textBlock; + _flyout.Opened += TestDropDownButtonFlyout_Opened; + _flyout.Closed += TestDropDownButtonFlyout_Closed; + } + + private void TestDropDownButton_Click(object sender, object e) + { + ClickCountTextBlock.Text = (++_clickCount).ToString(); + } + + private void TestDropDownButtonFlyout_Opened(object sender, object e) + { + FlyoutOpenedCountTextBlock.Text = (++_flyoutOpenedCount).ToString(); + } + + private void TestDropDownButtonFlyout_Closed(object sender, object e) + { + FlyoutClosedCountTextBlock.Text = (++_flyoutClosedCount).ToString(); + } + + private void SetFlyoutCheckbox_Checked(object sender, RoutedEventArgs e) + { + if (TestDropDownButton != null && _flyout != null) + { + TestDropDownButton.Flyout = _flyout; + } + } + + private void SetFlyoutCheckbox_Unchecked(object sender, RoutedEventArgs e) + { + if (TestDropDownButton != null) + { + TestDropDownButton.Flyout = null; + } + } + } +} diff --git a/src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml.Controls/DropDownButton.cs b/src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml.Controls/DropDownButton.cs index c72dd96e7f44..422f9195997e 100644 --- a/src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml.Controls/DropDownButton.cs +++ b/src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml.Controls/DropDownButton.cs @@ -2,12 +2,12 @@ #pragma warning disable 114 // new keyword hiding namespace Windows.UI.Xaml.Controls { - #if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__ + #if false || false || false || false || false [global::Uno.NotImplemented] #endif public partial class DropDownButton : global::Windows.UI.Xaml.Controls.Button { - #if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__ + #if false || false || false || false || false [global::Uno.NotImplemented] public DropDownButton() : base() { diff --git a/src/Uno.UI/UI/Xaml/Controls/DropDownButton/DropDownButton.cs b/src/Uno.UI/UI/Xaml/Controls/DropDownButton/DropDownButton.cs new file mode 100644 index 000000000000..29c709df8208 --- /dev/null +++ b/src/Uno.UI/UI/Xaml/Controls/DropDownButton/DropDownButton.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.UI.Xaml.Automation.Peers; + +namespace Windows.UI.Xaml.Controls +{ + public partial class DropDownButton : Button + { + public DropDownButton() + { + DefaultStyleKey = typeof(PersonPicture); + } + + protected override AutomationPeer OnCreateAutomationPeer() + { + return new DropDownButtonAutomationPeer(this); + } + + // - Missing + // m_flyoutPropertyChangedRevoker = RegisterPropertyChanged(*this, winrt::Button::FlyoutProperty(), { this, &DropDownButton::OnFlyoutPropertyChanged }); + + // RegisterFlyoutEvents(); + //} + + //void DropDownButton::RegisterFlyoutEvents() + //{ + // m_flyoutOpenedRevoker.revoke(); + // m_flyoutClosedRevoker.revoke(); + + // if (Flyout()) + // { + // m_flyoutOpenedRevoker = Flyout().Opened(winrt::auto_revoke, { this, &DropDownButton::OnFlyoutOpened }); + // m_flyoutClosedRevoker = Flyout().Closed(winrt::auto_revoke, { this, &DropDownButton::OnFlyoutClosed }); + // } + //} + + //bool DropDownButton::IsFlyoutOpen() + //{ + // return m_isFlyoutOpen; + //}; + + //void DropDownButton::OpenFlyout() + //{ + // if (auto flyout = Flyout()) + // { + // flyout.ShowAt(*this); + // } + //} + + //void DropDownButton::CloseFlyout() + //{ + // if (auto flyout = Flyout()) + // { + // flyout.Hide(); + // } + //} + + //void DropDownButton::OnFlyoutPropertyChanged(const winrt::DependencyObject& sender, const winrt::DependencyProperty& args) + //{ + // RegisterFlyoutEvents(); + //} + + //void DropDownButton::OnFlyoutOpened(const winrt::IInspectable& sender, const winrt::IInspectable& args) + //{ + // m_isFlyoutOpen = true; + // SharedHelpers::RaiseAutomationPropertyChangedEvent(*this, winrt::ExpandCollapseState::Collapsed, winrt::ExpandCollapseState::Expanded); + //} + + //void DropDownButton::OnFlyoutClosed(const winrt::IInspectable& sender, const winrt::IInspectable& args) + //{ + // m_isFlyoutOpen = false; + // SharedHelpers::RaiseAutomationPropertyChangedEvent(*this, winrt::ExpandCollapseState::Expanded, winrt::ExpandCollapseState::Collapsed); + //} + } +} diff --git a/src/Uno.UI/UI/Xaml/Controls/DropDownButton/DropDownButton.xaml b/src/Uno.UI/UI/Xaml/Controls/DropDownButton/DropDownButton.xaml new file mode 100644 index 000000000000..91182b426da3 --- /dev/null +++ b/src/Uno.UI/UI/Xaml/Controls/DropDownButton/DropDownButton.xaml @@ -0,0 +1,128 @@ + + + + + +