I've created the graphics for the user control as a vector graphic and imported it into Expression Design. So far everything worked w/o problems. However I then exported it as XAML and opened it in VS. The XAML consists of a canvas and several Paths. I created a user control in XAML, now I want a mouse click event, which is triggered if the user clicks on any of these paths. I could attach the same event to every path, but it would be more elegant to group the paths, is there a way to do this?
我已将用户控件的图形创建为矢量图形并将其导入Expression Design。到目前为止,一切都没有问题。然而,我然后将其导出为XAML并在VS中打开它。 XAML由画布和几个路径组成。我在XAML中创建了一个用户控件,现在我想要一个鼠标单击事件,如果用户单击这些路径中的任何一个,就会触发该事件。我可以将相同的事件附加到每个路径,但是将路径分组会更优雅,有没有办法做到这一点?
Also I was asking myself whether WPF can use a standard format for vector graphics like SVG.
另外我问自己WPF是否可以使用SVG等矢量图形的标准格式。
Below the XML code.
在XML代码下面。
<Canvas x:Name="Arrow" Width="40" Height="400" Canvas.Left="0" Canvas.Top="0">
<Path Width="11.432" Height="361.1" Canvas.Left="12.861" Canvas.Top="-2.666" StrokeThickness="12" StrokeLineJoin="Round" Stroke="#FFFF2800" Data="F1 M 310,130.967L 310,480.067"/>
<Path Width="6.75" Height="355.767" Canvas.Left="15.25" Canvas.Top="0" Stretch="Fill" StrokeThickness="6.66667" StrokeLineJoin="Round" Stroke="#FFFFFFFF" Data="F1 M 310,130.967L 310,480.067"/>
<Path Width="22.725" Height="30.4" Canvas.Left="6.363" Canvas.Top="351.1" Stretch="Fill" StrokeThickness="2.66667" StrokeMiterLimit="2.75" Stroke="#FFFF2800" Fill="#FFFF2800" Data="F1 M 310,507.8L 320.4,480.067L 299.6,480.067"/>
<Path Width="29.97" Height="2.667" Canvas.Left="4.107" Canvas.Top="2" Stretch="Fill" StrokeThickness="2.66667" StrokeMiterLimit="2.75" Stroke="#FFFF2800" Data="F1 M 296.133,130.967L 323.867,130.967"/>
</Canvas>
1 个解决方案
#1
I haven't got time to verify this, but off the top of my head, if you put your event on the canvas, and don't specify a background for it, then you should only get the click event when the user clicks on any of the paths it contains.
我没有时间来验证这一点,但是如果你把你的事件放在画布上,并且没有为它指定背景,那么你应该只在用户点击时获得点击事件。它包含的任何路径。
#1
I haven't got time to verify this, but off the top of my head, if you put your event on the canvas, and don't specify a background for it, then you should only get the click event when the user clicks on any of the paths it contains.
我没有时间来验证这一点,但是如果你把你的事件放在画布上,并且没有为它指定背景,那么你应该只在用户点击时获得点击事件。它包含的任何路径。