添加到现有 WPF 项目 (.NET 5) 时的路径转换

Paths transforming when added into existing WPF-Project (.NET 5)

我已经编码大约一年了,这似乎是我必须在这里问一个问题的时候,因为我想我正在失去理智。

我正在为 WPF 桌面应用程序编写“诊断选择器”,以简化骨折分类。

目标是在鼠标进入相应区域时为每个骨骼着色。 Here u can see the outline, here the Areas 并在骨骼中着色。

所以我使用 inkscape 将所有内容转换为路径,导出为 xaml,复制到用户控件中,使区域透明,折叠着色的可见性并在每个区域上添加 MouseEnter 和 MouseLeave 事件。

后面的代码:

public partial class UserControl1 : UserControl
{
    public UserControl1()
    {
        InitializeComponent();
    }
 private void Humeruslinks_MouseEnter(object sender, MouseEventArgs e)
    {
        HighlightOA.Visibility = Visibility.Visible;
    }

    private void Humeruslinks_MouseLeave(object sender, MouseEventArgs e)
    {
        HighlightOA.Visibility = Visibility.Collapsed;
    }

Xaml:

<UserControl x:Class="TestWPFApplication.UserControl1"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:TestWPFApplication"
         mc:Ignorable="d" 
         d:DesignHeight="450" d:DesignWidth="800">
<Viewbox Stretch="Uniform">
        <Canvas Name="DiagnosesFullCanvas" Width="296.96579" Height="762.27313">
            <Canvas.RenderTransform>
                <TranslateTransform X="0" Y="0"/>
            </Canvas.RenderTransform>
            <Canvas Name="backgroundDiagnosis_full">
                <Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path425" Fill="#FF000000">
                    <Path.Data>
                        <PathGeometry Figures="m 494 763.30887 c 0 -5.21874 0.12187 -5.53001 1.4682 -3.75 1.40978 1.8639 1.46946 1.83497 1.5 -0.72708 0.0175 -1.46752 0.30494 -3.38002 0.63879 -4.25 C 497.94083 753.7118 497.74713 [...] 885 0.40829 -0.217812 6.00127 -0.05731 6.41954 0.08087 0.21075 0.160959 0.23512 0.303746 0.0924 0.127813 -0.12773 0.193915 -1.2115 0.193915 -3.1793 z" FillRule="NonZero"/>
                            </Path.Data>
                            <Path.RenderTransform>
                                <TranslateTransform X="390.06275" Y="6.7268586"/>
                            </Path.RenderTransform>
                        </Path>...

...<Canvas Name="toggleAreaDiagnosis_full">
                <Path Name="TriggerHumerusLinks" Visibility="Visible" MouseEnter="Humeruslinks_MouseEnter" MouseLeave="Humeruslinks_MouseLeave"  Fill="Transparent" StrokeThickness="0" Stroke="#FF000000" StrokeMiterLimit="4" StrokeLineJoin="Round" Opacity="0.498645">
                    <Path.Data>
                        <PathGeometry Figures="m 586.58818 174.13612 26.49884 -3.92016 21.45993 113.13385 -25.94655 9.74993 -3.25242 -20.48787 -0.3312 -16.7253 z" FillRule="NonZero"/>
                    </Path.Data>
                    <Path.RenderTransform>
                        <TranslateTransform X="-390.06275" Y="-6.7268586"/>
                    </Path.RenderTransform>
                </Path>...

当我创建一个全新的 WPF 项目时,一切正常,完全没有问题。 问题是,当我尝试将用户控件包含在我现有的 WPF 项目中时,路径到处都是。参见 here(仅图片上的彩色区域)

我在 blend 和 vs 中试过了,它们分别是 19 和 22。试图在现有项目中创建一个新的用户控件并导入我在新项目中创建的用户控件。 我什至将所有路径转换为每种绝对和相对格式。 总是相同的结果。现在我有点失去理智了。

csproj 文件:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWpf>true</UseWpf>
</PropertyGroup>
<ItemGroup>
  <PackageReference Include="AutoMapper" Version="10.1.1" />
  <PackageReference Include="Caliburn.Micro" Version="4.0.173" />
  <PackageReference Include="Caliburn.Micro.Core" Version="4.0.173" />
  <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
  <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
  <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
  <PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
  <PackageReference Include="System.Runtime.WindowsRuntime.UI.Xaml" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
  <ProjectReference Include="..\KTDesktopUI.Library\KTDesktopUI.Library.csproj" />
</ItemGroup>
<ItemGroup>
  <None Update="appsettings.Development.json">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </None>
  <None Update="appsettings.json">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
  </None>
  <None Update="appsettings.Production.json">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </None>
</ItemGroup>

你们中有人知道我如何解决这个问题吗?是否可能有任何 nugets 与路径或 canvas 奇怪地交互?

感谢 rfmodulator,

到处都是旧代码绝对是正确的提示。 在资源字典中有一个旧的路径样式,这让我花了整个周末...

<Style TargetType="{x:Type Path}">
    <Setter Property="Fill" Value="Gray"/>
    <Setter Property="Width" Value="15"/>
    <Setter Property="Stretch" Value="Uniform"/>
</Style>

没有钥匙所以一切都搞砸了。 BooleanToVisibilityConverter 也将被设置。 非常感谢!!