admin管理员组文章数量:1292871
I want to change the transparency of the overlay displayed on the parent window when the ContentDialog is open. I am using WinUI 3. I have looked into generic.xaml and tried changing a few things, but there has been no effect at all.
I modified the following code, but I did not see any results.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
<SolidColorBrush x:Key="ContentDialogBackgroundThemeBrush" Color="Red" />
<SolidColorBrush x:Key="ContentDialogBorderThemeBrush" Color="Red" />
<SolidColorBrush x:Key="ContentDialogContentForegroundBrush" Color="Red" />
<SolidColorBrush x:Key="ContentDialogDimmingThemeBrush" Color="Red" />
<SolidColorBrush x:Key="SystemControlPageBackgroundBaseMediumBrush" Color="red" />
<SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="red" />
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="ContentDialogDimmingThemeBrush" Color="Red" />
<SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="Red" />
<StaticResource x:Key="ContentDialogLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="ContentDialogDimmingThemeBrush" Color="Red" />
<SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="Red" />
<StaticResource x:Key="ContentDialogLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Application.Resources>
I want to change the transparency of the overlay displayed on the parent window when the ContentDialog is open. I am using WinUI 3. I have looked into generic.xaml and tried changing a few things, but there has been no effect at all.
I modified the following code, but I did not see any results.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
<SolidColorBrush x:Key="ContentDialogBackgroundThemeBrush" Color="Red" />
<SolidColorBrush x:Key="ContentDialogBorderThemeBrush" Color="Red" />
<SolidColorBrush x:Key="ContentDialogContentForegroundBrush" Color="Red" />
<SolidColorBrush x:Key="ContentDialogDimmingThemeBrush" Color="Red" />
<SolidColorBrush x:Key="SystemControlPageBackgroundBaseMediumBrush" Color="red" />
<SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="red" />
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="ContentDialogDimmingThemeBrush" Color="Red" />
<SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="Red" />
<StaticResource x:Key="ContentDialogLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="ContentDialogDimmingThemeBrush" Color="Red" />
<SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="Red" />
<StaticResource x:Key="ContentDialogLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Application.Resources>
Share
Improve this question
edited Feb 13 at 5:06
Andrew KeepCoding
13.8k2 gold badges20 silver badges37 bronze badges
asked Feb 13 at 1:38
kintonkinton
3031 silver badge7 bronze badges
2
- You could try to set the Opacity property to the ContentDialog. – Jeaninez - MSFT Commented Feb 13 at 5:55
- Thank you. I tried the Opacity property, but it made the ContentDialog itself translucent. What I want to make translucent is the overlay on top of the main window behind the dialog. – kinton Commented Feb 13 at 9:19
1 Answer
Reset to default 1Try the following on the Opened
event:
private void ContentDialog_Opened(ContentDialog sender, ContentDialogOpenedEventArgs args)
{
if (VisualTreeHelper
.GetOpenPopupsForXamlRoot(this.XamlRoot)
.FirstOrDefault() is not Popup popup)
{
return;
}
if ((popup.Child as ContentDialog)?.FindAscendant<Canvas>() is not Canvas popupRoot ||
popupRoot.Children.OfType<Rectangle>().FirstOrDefault(x => x.Name is "SmokeLayerBackground") is not Rectangle smokeLayerBackground)
{
return;
}
// This will change the overlay background.
smokeLayerBackground.Fill = new SolidColorBrush()
{
Color = Colors.SkyBlue,
Opacity = 0.5,
};
}
You can learn about
SmokeLayerBacground
on the generic.xaml file.FindAscendant()
comes from the CommunityToolkit.WinUI.Extensions NuGet package.
本文标签: winui 3Change Parent Window Overlay Transparency with ContentDialogStack Overflow
版权声明:本文标题:winui 3 - Change Parent Window Overlay Transparency with ContentDialog - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741567243a2385799.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论