Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: 优化 Toast 样式
Browse files Browse the repository at this point in the history
Blinue committed Nov 15, 2023
1 parent 06581d6 commit 163255f
Showing 3 changed files with 22 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/Magpie.App/App.xaml
Original file line number Diff line number Diff line change
@@ -669,9 +669,6 @@

<x:Double x:Key="StandardIconSize">14</x:Double>

<!-- TeachingTip -->
<x:Double x:Key="TeachingTipMinWidth">0</x:Double>

<!-- ComboBox -->
<x:Double x:Key="SettingBoxMinWidth">220</x:Double>
<Style x:Key="ComboBoxSettingStyle"
21 changes: 21 additions & 0 deletions src/Magpie.App/MainPage.cpp
Original file line number Diff line number Diff line change
@@ -227,6 +227,27 @@ fire_and_forget MainPage::ShowToast(const hstring& message) {
ToastTextBlock().Text(message);
newTeachingTip.IsOpen(true);

// !!! HACK !!!
// 我们不想要 IsLightDismissEnabled,因为它会阻止用户和其他控件交互,但我们也不想要关闭按钮,于是
// 手动隐藏它。我们必须在模板加载完成后再做这些,但 TeachingTip 没有 Opening 事件,于是有了又一个
// workaround:监听 ToastTextBlock 的 LayoutUpdated 事件,它在 TeachingTip 显示前必然会被引发。
ToastTextBlock().LayoutUpdated([weak(weak_ref(newTeachingTip))](IInspectable const&, IInspectable const&) {
auto toastTeachingTip = weak.get();
if (!toastTeachingTip) {
return;
}

// 隐藏关闭按钮
if (DependencyObject closeButton = toastTeachingTip.GetTemplateChild(L"AlternateCloseButton")) {
closeButton.as<FrameworkElement>().Visibility(Visibility::Collapsed);
}

// 减小 Flyout 尺寸
if (DependencyObject container = toastTeachingTip.GetTemplateChild(L"TailOcclusionGrid")) {
container.as<FrameworkElement>().MinWidth(0.0);
}
});

weakTeachingTip = newTeachingTip;
}

3 changes: 1 addition & 2 deletions src/Magpie.App/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -9,8 +9,7 @@
mc:Ignorable="d">
<Grid>
<muxc:TeachingTip x:Name="ToastTeachingTip"
x:Load="False"
IsLightDismissEnabled="True">
x:Load="False">
<!-- Title 属性有主题错误 -->
<TextBlock x:Name="ToastTextBlock" />
</muxc:TeachingTip>

0 comments on commit 163255f

Please sign in to comment.