0

I've been coding for about year now and this seems to be the time I acutally have to ask a question here, cause I think I'm losing my mind.

I'm coding a "Diagnosis Picker" for a WPF-Desktop-App to simplify classification of fractures.

Goal is to color in each bone, when the mouse enters the according Area. Here u can see the outline, here the Areas and colored in bones.

So I converted everything into paths with inkscape, exported as xaml, copied into a usercontrol, made the areas transparent, collapsed visibility on the coloring in and added events for MouseEnter and MouseLeave on every Area.

Code behind:

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>...

The whole thing works fine when I create a brand new WPF-project, no problem at all. The thing is, when i try to include the usercontrol in my existing WPF-Project the paths go all over the place. See here (only the colored in areas on the picture)

I tried it in blend and vs, each of them 19 and 22. Tried to make a new usercontrol in the existing project and to import the one i made in the new project. I even converted all the paths to each absolut and relativ format. Always the same result. Now I am kind of losing my mind.

csproj-file:

<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>

Does anyone of you have an idea how i can solve the problem? Does maybe any of the nugets interact weirdly with paths or a canvas?

  • To me it looks like your transforms are off (based on the screen shot), is there any old debug code laying around? On a side note, I think you could do something kind of like [this](https://stackoverflow.com/a/34348472/1048799) to clean up your code behind and handle the mouse events in the xaml. Neat project though! – rfmodulator Jan 10 '22 at 00:48

1 Answers1

1

Thanks rfmodulator,

Old code laying around was absolutly the right hint. Had an old path-style in a resource-dict, that cost me an entire weekend...

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

No key so it messed everything up. BooleanToVisibilityConverter will be set up as well. Thanks so much!!

  • Hi, @Jonas Scheidig. Does this solution solve your problem? If it is solved, you could click ‘✔’ to accept it as an answer. It is helpful for community members to solve the similar problems. – Hui Liu-MSFT Jan 21 '22 at 02:59