I'm writing a WPF custom control that displays an overlay for loading processes. This custom control derives from ContentControl and reuses it's Effect dependency property to display a drop shadow.
我正在编写一个WPF自定义控件,用于显示加载进程的覆盖。这个自定义控件源自ContentControl并重用它的Effect dependency属性来显示一个投影。
However the drop shadow is unexpectely and unwantedly displayed two times. I've tried to find any logic to this, but do not know how to solve this. Anyone got a clue how to remove the shadow on the outer border?
然而,投下的阴影却出人意料地出现了两次。我已经试着找到了这方面的任何逻辑,但不知道如何解决这个问题。有人知道怎么去除外边界上的阴影吗?
LoadingOverlay.cs
LoadingOverlay.cs
public class LoadingOverlay : ContentControl
{
static LoadingOverlay()
{
Type currentType = typeof(LoadingOverlay);
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(
currentType,
new FrameworkPropertyMetadata(currentType));
}
}
Themes\Generic.xaml
主题\ Generic.xaml
<Style TargetType="local:LoadingOverlay">
<Setter Property="Background" Value="#BBFFFFFF" />
<Setter Property="BorderBrush" Value="#FF266ECC" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="0" />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:LoadingOverlay">
<Border Background="{TemplateBinding Background}" Effect="{x:Null}">
<Border Effect="{TemplateBinding Effect}" HorizontalAlignment="Center" VerticalAlignment="Center" Background="#FFFFFFFF" BorderBrush="#FF266ECC" BorderThickness="1">
<ContentPresenter VerticalAlignment="Center" Margin="15" RecognizesAccessKey="True" />
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
1 个解决方案
#1
0
Instead of Setting Effect at LoadingOverlay level, try setting Effect at inner Border level. Then you won't have to set the upper Border Effect to {x:null} as well. See below:
不要在LoadingOverlay级别设置效果,尝试在内部边界级别设置效果。然后,您不必将上边框效果设置为{x:null}。见下文:
<Style TargetType="local:LoadingOverlay">
<Setter Property="Background" Value="#BBFFFFFF" />
<Setter Property="BorderBrush" Value="#FF266ECC" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:LoadingOverlay">
<Border Background="{TemplateBinding Background}">
<Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="#FFFFFFFF" BorderBrush="#FF266ECC" BorderThickness="1">
<ContentPresenter VerticalAlignment="Center" Margin="15" RecognizesAccessKey="True" />
<Border.Effect>
<DropShadowEffect ShadowDepth="0" />
</Border.Effect>
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
#1
0
Instead of Setting Effect at LoadingOverlay level, try setting Effect at inner Border level. Then you won't have to set the upper Border Effect to {x:null} as well. See below:
不要在LoadingOverlay级别设置效果,尝试在内部边界级别设置效果。然后,您不必将上边框效果设置为{x:null}。见下文:
<Style TargetType="local:LoadingOverlay">
<Setter Property="Background" Value="#BBFFFFFF" />
<Setter Property="BorderBrush" Value="#FF266ECC" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:LoadingOverlay">
<Border Background="{TemplateBinding Background}">
<Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="#FFFFFFFF" BorderBrush="#FF266ECC" BorderThickness="1">
<ContentPresenter VerticalAlignment="Center" Margin="15" RecognizesAccessKey="True" />
<Border.Effect>
<DropShadowEffect ShadowDepth="0" />
</Border.Effect>
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>