【问题标题】:Setting width and height properties to auto in WPF causes button to blur在 WPF 中将宽度和高度属性设置为自动会导致按钮模糊
【发布时间】:2013-07-30 23:24:56
【问题描述】:

当我测试按钮的新界面时,我注意到在运行时出现模糊,而在设计时不存在。我将其追踪到汽车属性。

下图在运行时显示到按钮,左侧的高度和宽度设置为自动,右侧的高度和宽度手动设置。如您所见,左侧按钮上有一个模糊。

为什么会这样?有什么办法可以绕过吗?

谢谢。

相关 XAML:

        <Border Padding="1,1,1,1"  Height="Auto" Width="Auto">
            <!-- Border Properties -->
            <Border.Effect>
                <DropShadowEffect ShadowDepth="0" BlurRadius="8"/>
            </Border.Effect>
            <Border.Background>
                <SolidColorBrush x:Name="BorderBrush" Color="Gray"/>
            </Border.Background>

                <!-- End Properties -->


            <!-- Children -->
            <Grid>
                <!-- Properties -->
                <Grid.Background>
                    <LinearGradientBrush x:Name="BackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop x:Name="BackgroundLightColor" Color="#FF282828" Offset="0.572"/>
                        <GradientStop Color="#FF3C3C3C" Offset="0"/>
                    </LinearGradientBrush>
                </Grid.Background>
                <!-- End Properties -->
                <!-- Children -->
                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Content="{TemplateBinding Content}" Margin="20,5,20,5">
                    <TextBlock.Foreground>
                        <SolidColorBrush x:Name="ForegroundBrush" Color="#FFBBBBBB"/>
                    </TextBlock.Foreground>

                </ContentPresenter>
                <!-- End Children -->
            </Grid>
            <!-- End Children -->
        </Border>
    </ControlTemplate>
    <!-- End Template -->

左键:

<Border Padding="1,1,1,1"  Height="auto" Width="auto">

右键:

<Border Padding="1,1,1,1"  Height="29" Width="72">

【问题讨论】:

  • 什么?你的意思是“将属性设置为自动”吗?发布一些相关的 XAML。
  • 看起来像亚像素渲染问题,请尝试在您的应用程序或控件上设置SnapsToDevicePixelsUseLayoutRounding
  • 您是否尝试在“自动”按钮上将SnapsToDevicePixels 设置为true?
  • @sa_ddam213 谢谢。 UseLayoutRounding 有效。如何将此标记为答案?
  • @lvel97,我添加了评论作为答案,所以你可以标记为已回答

标签: wpf button runtime blurry


【解决方案1】:

看起来像亚像素渲染问题,请尝试在您的应用程序或控件上设置SnapsToDevicePixelsUseLayoutRounding

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-16
    • 1970-01-01
    • 2016-10-01
    • 2015-06-24
    • 2016-10-14
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    相关资源
    最近更新 更多