Browse Source

Merge pull request #6789 from AvaloniaUI/bugfix/transparent-popup-issue

Fix Default theme popup backgrounds
pull/6803/head
Dan Walmsley 5 years ago
committed by GitHub
parent
commit
4f70e1e970
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/Avalonia.Themes.Default/AutoCompleteBox.xaml
  2. 3
      src/Avalonia.Themes.Default/ComboBox.xaml
  3. 1
      src/Avalonia.Themes.Default/ContextMenu.xaml
  4. 2
      src/Avalonia.Themes.Default/FlyoutPresenter.xaml
  5. 2
      src/Avalonia.Themes.Default/MenuFlyoutPresenter.xaml
  6. 4
      src/Avalonia.Themes.Default/MenuItem.xaml
  7. 22
      src/Avalonia.Themes.Default/OverlayPopupHost.xaml
  8. 2
      src/Avalonia.Themes.Default/PopupRoot.xaml
  9. 17
      src/Avalonia.Themes.Fluent/Controls/OverlayPopupHost.xaml
  10. 1
      src/Avalonia.Themes.Fluent/Controls/PopupRoot.xaml
  11. 75
      tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs

3
src/Avalonia.Themes.Default/AutoCompleteBox.xaml

@ -21,7 +21,8 @@
MaxHeight="{TemplateBinding MaxDropDownHeight}" MaxHeight="{TemplateBinding MaxDropDownHeight}"
PlacementTarget="{TemplateBinding}" PlacementTarget="{TemplateBinding}"
IsLightDismissEnabled="True"> IsLightDismissEnabled="True">
<Border BorderBrush="{DynamicResource ThemeBorderMidBrush}" <Border Background="{DynamicResource ThemeBackgroundBrush}"
BorderBrush="{DynamicResource ThemeBorderMidBrush}"
BorderThickness="1"> BorderThickness="1">
<ListBox Name="PART_SelectingItemsControl" <ListBox Name="PART_SelectingItemsControl"
BorderThickness="0" BorderThickness="0"

3
src/Avalonia.Themes.Default/ComboBox.xaml

@ -69,7 +69,8 @@
MaxHeight="{TemplateBinding MaxDropDownHeight}" MaxHeight="{TemplateBinding MaxDropDownHeight}"
PlacementTarget="{TemplateBinding}" PlacementTarget="{TemplateBinding}"
IsLightDismissEnabled="True"> IsLightDismissEnabled="True">
<Border BorderBrush="{DynamicResource ThemeBorderMidBrush}" <Border Background="{DynamicResource ThemeBackgroundBrush}"
BorderBrush="{DynamicResource ThemeBorderMidBrush}"
BorderThickness="1"> BorderThickness="1">
<ScrollViewer HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" <ScrollViewer HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"> VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">

1
src/Avalonia.Themes.Default/ContextMenu.xaml

@ -1,4 +1,5 @@
<Style xmlns="https://github.com/avaloniaui" Selector="ContextMenu"> <Style xmlns="https://github.com/avaloniaui" Selector="ContextMenu">
<Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/>
<Setter Property="BorderThickness" Value="1"/> <Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="4,2"/> <Setter Property="Padding" Value="4,2"/>

2
src/Avalonia.Themes.Default/FlyoutPresenter.xaml

@ -2,7 +2,7 @@
<Style Selector="FlyoutPresenter"> <Style Selector="FlyoutPresenter">
<Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" /> <Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="Background" Value="Transparent" /> <Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}" /> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}" />
<Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderThickness" Value="1" />
<Setter Property="Padding" Value="4" /> <Setter Property="Padding" Value="4" />

2
src/Avalonia.Themes.Default/MenuFlyoutPresenter.xaml

@ -1,6 +1,6 @@
<Styles xmlns="https://github.com/avaloniaui"> <Styles xmlns="https://github.com/avaloniaui">
<Style Selector="MenuFlyoutPresenter"> <Style Selector="MenuFlyoutPresenter">
<Setter Property="Background" Value="Transparent" /> <Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}" /> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}" />
<Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderThickness" Value="1" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" /> <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />

4
src/Avalonia.Themes.Default/MenuItem.xaml

@ -62,7 +62,7 @@
PlacementMode="Right" PlacementMode="Right"
IsLightDismissEnabled="False" IsLightDismissEnabled="False"
IsOpen="{TemplateBinding IsSubMenuOpen, Mode=TwoWay}"> IsOpen="{TemplateBinding IsSubMenuOpen, Mode=TwoWay}">
<Border Background="{TemplateBinding Background}" <Border Background="{DynamicResource ThemeBackgroundBrush}"
BorderBrush="{DynamicResource ThemeBorderMidBrush}" BorderBrush="{DynamicResource ThemeBorderMidBrush}"
BorderThickness="{TemplateBinding BorderThickness}"> BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer Classes="menuscroller"> <ScrollViewer Classes="menuscroller">
@ -113,7 +113,7 @@
IsLightDismissEnabled="True" IsLightDismissEnabled="True"
OverlayInputPassThroughElement="{Binding $parent[Menu]}" OverlayInputPassThroughElement="{Binding $parent[Menu]}"
IsOpen="{TemplateBinding IsSubMenuOpen, Mode=TwoWay}"> IsOpen="{TemplateBinding IsSubMenuOpen, Mode=TwoWay}">
<Border Background="{TemplateBinding Background}" <Border Background="{DynamicResource ThemeBackgroundBrush}"
BorderBrush="{DynamicResource ThemeBorderMidBrush}" BorderBrush="{DynamicResource ThemeBorderMidBrush}"
BorderThickness="{TemplateBinding BorderThickness}"> BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer Classes="menuscroller"> <ScrollViewer Classes="menuscroller">

22
src/Avalonia.Themes.Default/OverlayPopupHost.xaml

@ -1,23 +1,21 @@
<Style xmlns="https://github.com/avaloniaui" <Style xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Selector="OverlayPopupHost"> Selector="OverlayPopupHost">
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}"/> <Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}" />
<Setter Property="FontSize" Value="{DynamicResource FontSizeNormal}"/> <Setter Property="FontSize" Value="{DynamicResource FontSizeNormal}" />
<Setter Property="FontFamily" Value="{x:Static FontFamily.Default}" /> <Setter Property="FontFamily" Value="{x:Static FontFamily.Default}" />
<Setter Property="FontWeight" Value="400" /> <Setter Property="FontWeight" Value="400" />
<Setter Property="FontStyle" Value="Normal" /> <Setter Property="FontStyle" Value="Normal" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Panel> <!-- Do not forget to update Templated_Control_With_Popup_In_Template_Should_Set_TemplatedParent test -->
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" /> <VisualLayerManager IsPopup="True">
<VisualLayerManager IsPopup="True"> <ContentPresenter Name="PART_ContentPresenter"
<ContentPresenter Name="PART_ContentPresenter" Background="{TemplateBinding Background}"
Background="{TemplateBinding Background}" ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}"
Content="{TemplateBinding Content}" Padding="{TemplateBinding Padding}"/>
Padding="{TemplateBinding Padding}"/> </VisualLayerManager>
</VisualLayerManager>
</Panel>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
</Style> </Style>

2
src/Avalonia.Themes.Default/PopupRoot.xaml

@ -1,6 +1,8 @@
<Style xmlns="https://github.com/avaloniaui" <Style xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Selector="PopupRoot"> Selector="PopupRoot">
<Setter Property="Background" Value="{x:Null}"/>
<Setter Property="TransparencyLevelHint" Value="Transparent" />
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}"/> <Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}"/>
<Setter Property="FontSize" Value="{DynamicResource FontSizeNormal}"/> <Setter Property="FontSize" Value="{DynamicResource FontSizeNormal}"/>
<Setter Property="FontFamily" Value="{x:Static FontFamily.Default}" /> <Setter Property="FontFamily" Value="{x:Static FontFamily.Default}" />

17
src/Avalonia.Themes.Fluent/Controls/OverlayPopupHost.xaml

@ -6,16 +6,13 @@
<Setter Property="FontStyle" Value="Normal" /> <Setter Property="FontStyle" Value="Normal" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Panel> <VisualLayerManager IsPopup="True">
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" /> <ContentPresenter Name="PART_ContentPresenter"
<VisualLayerManager IsPopup="True"> Background="{TemplateBinding Background}"
<ContentPresenter Name="PART_ContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}"
Background="{TemplateBinding Background}" Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" Padding="{TemplateBinding Padding}"/>
Content="{TemplateBinding Content}" </VisualLayerManager>
Padding="{TemplateBinding Padding}"/>
</VisualLayerManager>
</Panel>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
</Style> </Style>

1
src/Avalonia.Themes.Fluent/Controls/PopupRoot.xaml

@ -1,6 +1,7 @@
<Styles xmlns="https://github.com/avaloniaui" <Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style Selector="PopupRoot"> <Style Selector="PopupRoot">
<Setter Property="Background" Value="{x:Null}"/>
<Setter Property="TransparencyLevelHint" Value="Transparent" /> <Setter Property="TransparencyLevelHint" Value="Transparent" />
<Setter Property="Foreground" Value="{DynamicResource SystemControlForegroundBaseHighBrush}"/> <Setter Property="Foreground" Value="{DynamicResource SystemControlForegroundBaseHighBrush}"/>
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}"/> <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}"/>

75
tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs

@ -294,6 +294,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
[Fact] [Fact]
public void Templated_Control_With_Popup_In_Template_Should_Set_TemplatedParent() public void Templated_Control_With_Popup_In_Template_Should_Set_TemplatedParent()
{ {
// Test uses OverlayPopupHost default template
using (CreateServices()) using (CreateServices())
{ {
PopupContentControl target; PopupContentControl target;
@ -316,33 +317,63 @@ namespace Avalonia.Controls.UnitTests.Primitives
var children = popupRoot.GetVisualDescendants().ToList(); var children = popupRoot.GetVisualDescendants().ToList();
var types = children.Select(x => x.GetType().Name).ToList(); var types = children.Select(x => x.GetType().Name).ToList();
Assert.Equal( if (UsePopupHost)
new[] {
{ Assert.Equal(
"Panel", new[]
"Border", {
"VisualLayerManager", "VisualLayerManager",
"ContentPresenter", "ContentPresenter",
"ContentPresenter", "ContentPresenter",
"Border", "Border",
}, },
types); types);
}
else
{
Assert.Equal(
new[]
{
"Panel",
"Border",
"VisualLayerManager",
"ContentPresenter",
"ContentPresenter",
"Border",
},
types);
}
var templatedParents = children var templatedParents = children
.OfType<IControl>() .OfType<IControl>()
.Select(x => x.TemplatedParent).ToList(); .Select(x => x.TemplatedParent).ToList();
Assert.Equal( if (UsePopupHost)
new object[] {
{ Assert.Equal(
popupRoot, new object[]
popupRoot, {
popupRoot, popupRoot,
popupRoot, popupRoot,
target, target,
null, null,
}, },
templatedParents); templatedParents);
}
else
{
Assert.Equal(
new object[]
{
popupRoot,
popupRoot,
popupRoot,
popupRoot,
target,
null,
},
templatedParents);
}
} }
} }

Loading…
Cancel
Save