-
Notifications
You must be signed in to change notification settings - Fork 678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/expander #3492
Feature/expander #3492
Changes from 50 commits
12e49c6
157fdeb
c9aa3a7
1c3f5dc
e6c22e1
7c9784a
6b58141
6f9e241
fa0703f
dfd874d
d40b5de
84a55b2
319359a
bbe4eec
d59ab8b
d00cb30
34b1595
68bc096
f721f0d
260ee1f
d1d3c95
b8abb85
9e2ae0b
0b6295d
8e1c504
886872e
4d95a09
e2df11e
79d8a7a
90a6262
53b7434
f6b01f0
c719010
e29e26f
4c3975b
b24ed5f
4241e74
aa7de67
ffcb53e
1ce7329
556411e
d80afea
941fa34
ebc695b
b2207f5
97653f3
304344c
ab8d115
228a119
ba4dbc8
8304b7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
#include "pch.h" | ||
#include "common.h" | ||
#include "Expander.h" | ||
#include "RuntimeProfiler.h" | ||
#include "ResourceAccessor.h" | ||
#include "ExpanderAutomationPeer.h" | ||
#include "Utils.h" | ||
#include "winnls.h" | ||
|
||
static constexpr auto c_expanderHeader = L"ExpanderHeader"sv; | ||
|
||
Expander::Expander() | ||
{ | ||
__RP_Marker_ClassById(RuntimeProfiler::ProfId_Expander); | ||
|
||
SetDefaultStyleKey(this); | ||
} | ||
|
||
winrt::AutomationPeer Expander::OnCreateAutomationPeer() | ||
{ | ||
return winrt::make<ExpanderAutomationPeer>(*this); | ||
} | ||
|
||
void Expander::OnApplyTemplate() | ||
{ | ||
winrt::IControlProtected controlProtected{ *this }; | ||
|
||
if (auto toggleButton = GetTemplateChildT<winrt::Control>(c_expanderHeader, *this)) | ||
{ | ||
// We will do 2 things with the toggle button's peer: | ||
// 1. Set the events source of the toggle button peer to | ||
// the expander's automation peer. This is is because we | ||
// don't want to announce the toggle button's on/off property | ||
// changes, but the expander's expander/collapse property changes | ||
// (or on the events source that's set, if it's set) and | ||
// | ||
// 2. Set the expander's automation properties name to the | ||
// toggleButton's in case the expander doesn't have one. This just follows | ||
// what WPF does. | ||
if (winrt::AutomationPeer toggleButtonPeer = winrt::FrameworkElementAutomationPeer::FromElement(toggleButton)) | ||
{ | ||
// 1. Set the events source of the toggle button peer to the expander's. | ||
if (winrt::AutomationPeer expanderPeer = winrt::FrameworkElementAutomationPeer::FromElement(*this)) | ||
{ | ||
auto expanderEventsSource = expanderPeer.EventsSource() != nullptr ? | ||
expanderPeer.EventsSource() : | ||
expanderPeer; | ||
toggleButtonPeer.EventsSource(expanderEventsSource); | ||
} | ||
|
||
// 2. If the expander doesn't have any AutomationProperties.Name set, | ||
// we will try setting one based on the header. This is how | ||
// WPF's expanders work. | ||
if (winrt::AutomationProperties::GetName(*this).empty() | ||
&& !toggleButtonPeer.GetNameCore().empty()) | ||
{ | ||
winrt::AutomationProperties::SetName(*this, toggleButtonPeer.GetNameCore()); | ||
} | ||
} | ||
} | ||
|
||
UpdateExpandState(false); | ||
UpdateExpandDirection(false); | ||
ejserna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
|
||
void Expander::RaiseExpandingEvent(const winrt::Expander& container) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. container is never used, why is it here? |
||
{ | ||
m_expandingEventSource(*this, nullptr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invoking an event without arguments?? |
||
} | ||
|
||
void Expander::RaiseCollapsedEvent(const winrt::Expander& container) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. container is never used, why is it here? |
||
{ | ||
m_collapsedEventSource(*this, nullptr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invoking an event without arguments?? |
||
} | ||
|
||
void Expander::OnIsExpandedPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& /*args*/) | ||
{ | ||
if (IsExpanded()) | ||
{ | ||
RaiseExpandingEvent(*this); | ||
ejserna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
else | ||
{ | ||
RaiseCollapsedEvent(*this); | ||
} | ||
UpdateExpandState(true); | ||
} | ||
|
||
void Expander::OnExpandDirectionPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& /*args*/) | ||
{ | ||
UpdateExpandDirection(true); | ||
} | ||
|
||
void Expander::UpdateExpandDirection(bool useTransitions) | ||
{ | ||
const auto direction = ExpandDirection(); | ||
switch (direction) | ||
{ | ||
case winrt::ExpandDirection::Down: | ||
winrt::VisualStateManager::GoToState(*this, L"Down", useTransitions); | ||
break; | ||
case winrt::ExpandDirection::Up: | ||
winrt::VisualStateManager::GoToState(*this, L"Up", useTransitions); | ||
break; | ||
} | ||
} | ||
|
||
void Expander::UpdateExpandState(bool useTransitions) | ||
{ | ||
const auto isExpanded = IsExpanded(); | ||
if (isExpanded) | ||
{ | ||
winrt::VisualStateManager::GoToState(*this, L"Expanded", useTransitions); | ||
} | ||
else | ||
{ | ||
winrt::VisualStateManager::GoToState(*this, L"Collapsed", useTransitions); | ||
} | ||
|
||
if (winrt::AutomationPeer peer = winrt::FrameworkElementAutomationPeer::FromElement(*this)) | ||
{ | ||
auto expanderPeer = peer.as<ExpanderAutomationPeer>(); | ||
expanderPeer->RaiseExpandCollapseAutomationEvent( | ||
isExpanded ? | ||
winrt::ExpandCollapseState::Expanded : | ||
winrt::ExpandCollapseState::Collapsed | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
#pragma once | ||
|
||
#include "pch.h" | ||
#include "common.h" | ||
|
||
#include "Expander.g.h" | ||
#include "Expander.properties.h" | ||
|
||
class Expander : | ||
public ReferenceTracker<Expander, winrt::implementation::ExpanderT>, | ||
public ExpanderProperties | ||
{ | ||
public: | ||
Expander(); | ||
~Expander() {} | ||
|
||
// IUIElement | ||
virtual winrt::AutomationPeer OnCreateAutomationPeer(); | ||
|
||
// IFrameworkElement | ||
void OnApplyTemplate(); | ||
|
||
|
||
void RaiseExpandingEvent(const winrt::Expander& container); | ||
void RaiseCollapsedEvent(const winrt::Expander& container); | ||
|
||
void OnIsExpandedPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args); | ||
void OnExpandDirectionPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args); | ||
|
||
private: | ||
void UpdateExpandDirection(bool useTransitions); | ||
void UpdateExpandState(bool useTransitions); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"This is is because" Typo