模糊装饰器 WPF Xaml

6

我真的无法想通,使用相同的控件模板,我的面板中一个元素上却出现了模糊的装饰层:

enter image description here

控件模板:

<ControlTemplate x:Key="validationErrorTemplateBubble" >
<DockPanel >
    <Grid DockPanel.Dock="Bottom" Margin="10,0,0,0" >
        <Grid.Effect>
            <DropShadowEffect ShadowDepth="2" Direction="315" />
        </Grid.Effect>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Border Grid.Row="1" BorderBrush="Gray" BorderThickness="1" CornerRadius="5" Margin="0,-1.6,0,0">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFE7E8F1" Offset="1"/>
                    <GradientStop Color="White"/>
                    <GradientStop Color="#FFF3F4F6" Offset="0.472"/>
                </LinearGradientBrush>
            </Border.Background>

            <Grid>
                <WrapPanel VerticalAlignment="Center" Margin="5,5,10,5">
                    <Image Source="/Sesam;component/Modules/Images/wrongsmall.png" Height="15" Width="15" />
                    <TextBlock Foreground="Red" FontSize="12" Margin="5,0,0,0" Text="{Binding ElementName=ErrorAdorner, Path=AdornedElement.(Validation.Errors).CurrentItem.ErrorContent}" />
                </WrapPanel>
                <ContentPresenter Margin="5" Grid.Column="1" Grid.Row="1"/>
            </Grid>
        </Border>
        <Path Data="M306.375,133.125L306.375,100.875L335.75,133.25" Stroke="Gray" Height="15" Fill="White" StrokeThickness="1" Stretch="Uniform"  Margin="10,0,0,0"  HorizontalAlignment="Left" VerticalAlignment="Center"/>
    </Grid>
    <AdornedElementPlaceholder x:Name="ErrorAdorner" />
</DockPanel>

非模糊文本框代码:

<TextBox BorderThickness="0" VerticalAlignment="Center" Width="150" Padding="3" Margin="8,0,0,0" Foreground="{StaticResource myDarkBlue}" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListView}}, Path=DataContext.encTypeValidation, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource validationErrorTemplateBubble}" HorizontalAlignment="Left"  >
<TextBox.Style>
    <Style TargetType="{x:Type TextBox}">
        <Setter Property="Visibility" Value="Collapsed" />
        <Style.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}, Path=IsSelected}" Value="True" />
                    <Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListView}}, Path=DataContext.editClicked}" Value="True" />
                </MultiDataTrigger.Conditions>
                <Setter Property="Visibility" Value="Visible" />
            </MultiDataTrigger>
        </Style.Triggers>
    </Style>
</TextBox.Style>

模糊的文本框代码:

    <Grid>
    <WrapPanel>
        <TextBox x:Name="tbox" Text="{Binding encTypeValidation, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Foreground="{StaticResource myTextBoxColor}" Validation.ErrorTemplate="{StaticResource validationErrorTemplateBubble}" PreviewMouseDown="tbox_PreviewMouseDown" Width="200" >
            <TextBox.InputBindings>
                <MouseBinding Gesture="LeftClick" Command="{Binding addBoxClicked}" />
            </TextBox.InputBindings>
        </TextBox>
    </WrapPanel>
</Grid>

关于它的渲染方式,第一个(非模糊)在"ListViewItem"控件模板中,另一个是一个用户控件。

有什么想法吗?

已解决

通过将UseLayoutRounding="True"添加到父控件,例如ContentControl来解决问题!

谢谢Aybe!

        <Grid Grid.Row="2" Background="{StaticResource myLightGrey}" >
        <Border  BorderBrush="{StaticResource myLightGrey}" BorderThickness="0,1,1,0">
            <ContentControl x:Name="AddPanel" VerticalAlignment="Center" HorizontalAlignment="Center" UseLayoutRounding="True"/>
        </Border>
    </Grid>

Fixed


尝试使用 UseLayoutRounding 和 SnapToDevicePixels。 - aybe
提高您的声望以便将来能够进行内联截图。祝好运。 - Bobby
@Aybe 在发布之前尝试了 SnapToDevicePixels 对几乎所有元素进行操作,认为可能与此有关,将尝试 UseLayoutRounding(虽然我认为我已经尝试过),您会将其应用于哪个元素?我想是在 Adorner 控件模板中吧。 - Tim Earl
1
@Aybe 谢谢!我在父控件(即ContentControl)中添加了UseLayoutRounding,现在渲染效果非常完美,非常感谢 :) - Tim Earl
很酷,你的图片也修好了。 - aybe
显示剩余3条评论
1个回答

1
将UseLayoutRounding="True"添加到父控件可解决渲染问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接