内容控件旋转装饰器渲染

32

我最近遇到了一些问题:在我的WPF应用程序中,我实现了一个小型设计器,你可以将元素放置在画布上,并对它们进行移动、缩放和旋转。

在搜索网络时,我发现了这个解决方案,该解决方案通过System.Windows.Controls.Primitives.Thumb类实现了移动、缩放和旋转,因此我认为我只需要将这个解决方案调整到我的应用程序中并继续前进就可以了。问题是,在我的机器上一切正常,但在其他人的机器上存在一些渲染问题。我截取了一张屏幕截图来说明:

screenshot

我使用的是Windows 7,即使在其他运行Windows 7的机器上,也会出现错误的渲染。我在我的机器上使用Windows XP和其他兼容性设置运行应用程序,但我无法重现此错误。这是怎么回事?我可能做错了什么?

这是我用于内容控件样式的xaml文件:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:s="clr-namespace:COMPANY.WPUI.LayoutDesignModel.Thumbs">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="MoveThumb.xaml"/>
        <ResourceDictionary Source="ResizeDecorator.xaml"/>
        <ResourceDictionary Source="RotateDecorator.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="DesignerItemStyle" TargetType="ContentControl">
        <Setter Property="MinHeight" Value="50"/>
        <Setter Property="MinWidth" Value="50"/>
        <Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ContentControl">
                    <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                        <Control Name="RotateDecorator" Template="{StaticResource RotateDecoratorTemplate}" Visibility="Collapsed"/>
                        <s:MoveThumb Template="{StaticResource MoveThumbTemplate}" Cursor="SizeAll"/>
                        <Control x:Name="ResizeDecorator" Template="{StaticResource ResizeDecoratorTemplate}" Visibility="Collapsed"/>
                        <ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Selector.IsSelected" Value="True">
                            <Setter TargetName="ResizeDecorator" Property="Visibility" Value="Visible"/>
                            <Setter TargetName="RotateDecorator" Property="Visibility" Value="Visible"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

这是一个RotateDecorator.xaml文件,它导致了一些问题:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:s="clr-namespace:COMPANY.WPUI.LayoutDesignModel.Thumbs">

    <Style TargetType="{x:Type s:RotateThumb}">
        <Setter Property="Cursor" Value="Hand"/>
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type s:RotateThumb}">
                    <Grid Width="30" Height="30">
                        <Ellipse Width="30" Height="30" Fill="#B0B0BB" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="RotateDecoratorTemplate" TargetType="{x:Type Control}">
        <Grid>
            <s:RotateThumb Margin="-18,-18,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"/>
            <s:RotateThumb Margin="0,-18,-18,0" VerticalAlignment="Top" HorizontalAlignment="Right" />
            <s:RotateThumb Margin="0,0,-18,-18" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
            <s:RotateThumb Margin="-18,0,0,-18" VerticalAlignment="Bottom" HorizontalAlignment="Left" />
        </Grid>
    </ControlTemplate>
</ResourceDictionary>
2个回答

0
每当看到这种情况,我首先想到的是显卡。某些显卡可能会出现奇怪的行为,尤其是如果它们的驱动程序未正确安装或已过时。

0
这是由于MergedDictionaries引起的。Diagram Designer项目将Move、Resize和Rotate操作分成三个单独的字典。从截图中可以看到已加载了resize缩略图。在我的情况下,移动操作也起作用,但像问题一样,旋转拇指没有显示出来。没有错误被抛出,但使用Snoop进行检查表明它无法找到旋转字典。
这个解决方案扩展了我上面所讨论的内容: https://dev59.com/2mQn5IYBdhLWcg3wJ0UO#17083360 解决方法:将资源字典合并为一个单独的资源字典。

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