gpt4 book ai didi

c# - 在 WPF 自定义控件上多次应用 DropShadowEffect

转载 作者:太空宇宙 更新时间:2023-11-03 15:25:40 25 4
gpt4 key购买 nike

我正在编写一个 WPF 自定义控件,它显示加载过程的叠加层。此自定义控件源自 ContentControl并重复使用它的 Effect显示投影的依赖属性。

然而,投影意外且意外地显示了两次。我试图找到任何逻辑,但不知道如何解决这个问题。有人知道如何去除外边框上的阴影吗?

Shadow displayed on outer border and inner border.

LoadingOverlay.cs

public class LoadingOverlay : ContentControl
{
static LoadingOverlay()
{
Type currentType = typeof(LoadingOverlay);
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(
currentType,
new FrameworkPropertyMetadata(currentType));
}
}

Themes\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>

最佳答案

尝试在内部边框级别设置效果,而不是在 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>

关于c# - 在 WPF 自定义控件上多次应用 DropShadowEffect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35428489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com