模糊装饰器 WPF Xaml

Blurry Adorner WPF Xaml

我这辈子都弄不明白,使用相同的控件模板,我在面板中的一个元素上得到了一个模糊的装饰器:

控制模板:

<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" 控件模板中,另一个是 userControl..

有什么想法吗?

固定

通过向父控件添加 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>

在父容器控件中添加 UseLayoutRounding="True" 解决了渲染问题。