Skip to content

Commit

Permalink
[Experimental TitleBar] Collapse TitleText when empty (#6326)
Browse files Browse the repository at this point in the history
* Add title property changed handler and visual states to collapsed empty title

* Remove param from method and get the Title directly.
  • Loading branch information
SamChaps authored Nov 17, 2021
1 parent 2562ac6 commit fc02d50
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions dev/TitleBar/TitleBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void TitleBar::OnApplyTemplate()
UpdateIcon();
UpdateBackButton();
UpdateTheme();
UpdateTitle();
}

void TitleBar::OnBackButtonClick(winrt::IInspectable const& sender, winrt::RoutedEventArgs const& args)
Expand All @@ -119,6 +120,11 @@ void TitleBar::OnCustomContentPropertyChanged(const winrt::DependencyPropertyCha
UpdateHeight();
}

void TitleBar::OnTitlePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args)
{
UpdateTitle();
}

void TitleBar::OnSizeChanged(const winrt::IInspectable& sender, const winrt::SizeChangedEventArgs& args)
{
const auto titleTextBlock = m_titleTextBlock.get();
Expand Down Expand Up @@ -264,3 +270,17 @@ void TitleBar::UpdateTheme()
}
}
}

void TitleBar::UpdateTitle()
{
const winrt::hstring titleText = Title();
if (titleText.empty())
{
winrt::VisualStateManager::GoToState(*this, L"TitleTextCollapsed", false);
}
else
{
winrt::VisualStateManager::GoToState(*this, L"TitleTextVisible", false);
}
}

2 changes: 2 additions & 0 deletions dev/TitleBar/TitleBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class TitleBar :
void OnIconSourcePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnIsBackButtonVisiblePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnCustomContentPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnTitlePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);

private:
void UpdateVisibility();
Expand All @@ -35,6 +36,7 @@ class TitleBar :
void UpdateBackButton();
void UpdateHeight();
void UpdateTheme();
void UpdateTitle();

void OnWindowActivated(const winrt::IInspectable& sender, const winrt::WindowActivatedEventArgs& args);
void OnTitleBarMetricsChanged(const winrt::IInspectable& sender, const winrt::IInspectable& args);
Expand Down
1 change: 1 addition & 0 deletions dev/TitleBar/TitleBar.idl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ unsealed runtimeclass TitleBar : Windows.UI.Xaml.Controls.Control
{
TitleBar();

[MUX_PROPERTY_CHANGED_CALLBACK(TRUE)]
String Title{ get; set; };

[MUX_PROPERTY_CHANGED_CALLBACK(TRUE)]
Expand Down
9 changes: 9 additions & 0 deletions dev/TitleBar/TitleBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
</VisualState>
</VisualStateGroup>

<VisualStateGroup x:Name="TitleTextVisibilityGroup">
<VisualState x:Name="TitleTextVisible" />
<VisualState x:Name="TitleTextCollapsed">
<VisualState.Setters>
<Setter Target="TitleText.Visibility" Value="Collapsed" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>

<VisualStateGroup x:Name="FullScreenGroup">
<VisualState x:Name="TitleBarVisible"/>
<VisualState x:Name="TitleBarCollapsed">
Expand Down

0 comments on commit fc02d50

Please sign in to comment.