WPF .net - 按钮在缩放时看起来不同
WPF .net - Buttons look different when zoomed
我正在 visual studio 中开发一个 WPF .net 应用程序,但遇到一个问题,即按钮及其着色器看起来会因我的放大程度而有所不同。这也适用于更改显示器的分辨率。我附上了一些说明该问题的屏幕截图。有人知道这里发生了什么吗?
我正在为 visual studio
使用 WPF-Neumorphism-Plus 套件
我的 XAML(我只包含样式内容,但如果需要可以添加更多内容)
<Style x:Key="Button_Background" TargetType="Border">
<Setter Property="Background" Value="#ffffff"/>
<Setter Property="CornerRadius" Value="50"/>
<Setter Property="Opacity" Value="0.2"/>
</Style>
<Style x:Key="Text_Format" TargetType="Label">
<Setter Property="FontFamily" Value="Dubai Medium"/>
<Setter Property="FontSize" Value="40"/>
<Setter Property="Foreground" Value="#ffffff"/>
</Style>
<Style x:Key="NeumorphismStyle_light" TargetType="Button">
<Setter Property="FontFamily" Value="Dubai Medium"/>
<Setter Property="Foreground" Value="#ffffff"/>
<Setter Property="FontSize" Value="40"/>
<Setter Property="Background" Value="#abccde"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Grid.Effect>
<WPF_Neumorphism_Plus:Neumorphism_Plus_Shader BorderRadius="25" BlurRadius="10" OffsetX="4" OffsetY="5" SpreadRadius="2"
PrimaryColor="#6d828f" SecondaryColor="#d5ebf7" />
</Grid.Effect>
<Rectangle Fill="{TemplateBinding Background}" RadiusX="25" RadiusY="25"/>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Tag" Value="on">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Grid.Effect>
<WPF_Neumorphism_Plus:Neumorphism_Plus_Shader BorderRadius="25" BlurRadius="6" OffsetX="5" OffsetY="3" SpreadRadius="0"
PrimaryColor="#81b376" SecondaryColor="#cff0c7" Inset="1"/>
</Grid.Effect>
<Rectangle Fill="{TemplateBinding Background}" RadiusX="25" RadiusY="25"/>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="#b7deab"/>
</Trigger>
<Trigger Property="Tag" Value="off">
<Setter Property="Background" Value="#abccde"/>
</Trigger>
</Style.Triggers>
</Style>
在我看来,这是基于视角问题(缩放与常规)。查看您提供的两张图片,带有 'D' 文本的按钮不会改变其视角。也许这是由于文本区域边缘和按钮边缘之间的环境区域。您是否尝试过分别更改按钮和文本项的背景?
这个问题我遇到过很多次,有一天我学会了一个简单的解决方法。
您所要做的就是在您的 ViewBox 中添加 Grid
,然后您必须将 ViewBox 设置为 StretchDirection="Both"
和 Stretch="Uniform"
XAML
<Viewbox StretchDirection="Both" Stretch="Uniform">
<Grid Height="720" Width="1280" >
<!-- Your XAML Code Here. -->
</Grid>
</ViewBox>
我知道您可能已经知道这一点,但请记住,您需要在 <Window/>
之间添加所有这些代码。另外我这里的网格是720p,你可以把它改成你想要的宽度和高度。
这样做是将网格添加到 ViewBox 中。当你放大时,它会均匀放大。
我正在 visual studio 中开发一个 WPF .net 应用程序,但遇到一个问题,即按钮及其着色器看起来会因我的放大程度而有所不同。这也适用于更改显示器的分辨率。我附上了一些说明该问题的屏幕截图。有人知道这里发生了什么吗?
我正在为 visual studio
使用 WPF-Neumorphism-Plus 套件我的 XAML(我只包含样式内容,但如果需要可以添加更多内容)
<Style x:Key="Button_Background" TargetType="Border"> <Setter Property="Background" Value="#ffffff"/> <Setter Property="CornerRadius" Value="50"/> <Setter Property="Opacity" Value="0.2"/> </Style> <Style x:Key="Text_Format" TargetType="Label"> <Setter Property="FontFamily" Value="Dubai Medium"/> <Setter Property="FontSize" Value="40"/> <Setter Property="Foreground" Value="#ffffff"/> </Style> <Style x:Key="NeumorphismStyle_light" TargetType="Button"> <Setter Property="FontFamily" Value="Dubai Medium"/> <Setter Property="Foreground" Value="#ffffff"/> <Setter Property="FontSize" Value="40"/> <Setter Property="Background" Value="#abccde"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <Grid.Effect> <WPF_Neumorphism_Plus:Neumorphism_Plus_Shader BorderRadius="25" BlurRadius="10" OffsetX="4" OffsetY="5" SpreadRadius="2" PrimaryColor="#6d828f" SecondaryColor="#d5ebf7" /> </Grid.Effect> <Rectangle Fill="{TemplateBinding Background}" RadiusX="25" RadiusY="25"/> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="Tag" Value="on"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <Grid.Effect> <WPF_Neumorphism_Plus:Neumorphism_Plus_Shader BorderRadius="25" BlurRadius="6" OffsetX="5" OffsetY="3" SpreadRadius="0" PrimaryColor="#81b376" SecondaryColor="#cff0c7" Inset="1"/> </Grid.Effect> <Rectangle Fill="{TemplateBinding Background}" RadiusX="25" RadiusY="25"/> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="Background" Value="#b7deab"/> </Trigger> <Trigger Property="Tag" Value="off"> <Setter Property="Background" Value="#abccde"/> </Trigger> </Style.Triggers> </Style>
在我看来,这是基于视角问题(缩放与常规)。查看您提供的两张图片,带有 'D' 文本的按钮不会改变其视角。也许这是由于文本区域边缘和按钮边缘之间的环境区域。您是否尝试过分别更改按钮和文本项的背景?
这个问题我遇到过很多次,有一天我学会了一个简单的解决方法。
您所要做的就是在您的 ViewBox 中添加 Grid
,然后您必须将 ViewBox 设置为 StretchDirection="Both"
和 Stretch="Uniform"
XAML
<Viewbox StretchDirection="Both" Stretch="Uniform">
<Grid Height="720" Width="1280" >
<!-- Your XAML Code Here. -->
</Grid>
</ViewBox>
我知道您可能已经知道这一点,但请记住,您需要在 <Window/>
之间添加所有这些代码。另外我这里的网格是720p,你可以把它改成你想要的宽度和高度。
这样做是将网格添加到 ViewBox 中。当你放大时,它会均匀放大。