19

我最近偶然发现了以下问题:在我的 WPF 应用程序中,我实现了一个小设计器,您可以在其中将元素放在画布上、移动、缩放和旋转它们。

在网上搜索时,我发现了以下解决此问题的方法。这个解决方案实现了按类移动、缩放和旋转,System.Windows.Controls.Primitives.Thumb所以我想我会根据我的应用程序调整这个解决方案并继续前进。问题是,虽然在我的机器上一切都很好,但在其他机器上却存在一些渲染问题。我已经截取了我所说的内容:

截屏

我正在使用 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>
4

2 回答 2

0

每当看到这样的东西,我首先想到的就是显卡。某些显卡可能会出现一些奇怪的行为,特别是如果它们的驱动程序未正确安装/更新。

于 2015-06-22T15:36:38.430 回答
0

这是由 MergedDictionaries 引起的。Diagram Designer Project 将 Move、Resize 和 Rotate 操作拆分为 3 个单独的字典。从屏幕截图中,您可以看到调整大小拇指已加载。在我的情况下,移动操作也有效,但就像问题一样,旋转拇指没有显示。没有抛出任何错误,但使用 Snoop 进行检查表明它无法找到旋转字典。

此解决方案扩展了我上面介绍的内容:https ://stackoverflow.com/a/17083360/978622

解决方法:将资源字典组合成一个资源字典。

于 2015-06-30T17:13:38.487 回答