[英]Path and XAML controls
In order to show an object on a toolbox and allow user to drag/drop it on canvas I am using following control: 为了在工具箱上显示对象并允许用户将其拖放到画布上,我使用以下控件:
<HeaderedItemsControl x:Key="itemABC"
Width="100"
Height="100"
Canvas.Left="210"
Canvas.Top="220"
Margin="0,0,0,0"
Style="{StaticResource ABC_Style}">
</HeaderedItemsControl>
and 和
In style have defined: 在风格上有定义:
<Style x:Key="ABC_Style" TargetType="HeaderedItemsControl">
<Setter Property="Data" Value="M10.395,0.5 L30.237,0.5 30.237,5.0359993 39.499999,5.0359993 39.499999,22.75 30.237,22.75 30.237,42.660999 39.499999,42.660999 39.499999,60.375 30.237,60.375 30.237,65 10.395,65 10.395,58.124999 0.5,58.124999 0.5,10 10.395,10 z"/>
</Style>
However, the problem is that HeaderdItemsControl has no Path attribute (as far as I know) so I'm wondering what other option I can have here. 但是,问题是HeaderdItemsControl没有Path属性(据我所知),所以我想知道我在这里还能有什么其他选择。
In fact, I need to show a path inside a HeaderedItemsControl in XAML. 实际上,我需要在XAML中显示HeaderedItemsControl内部的路径。
Thanks. 谢谢。
This example works: 此示例有效:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="HeaderedItemsControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type HeaderedItemsControl}">
<StackPanel>
<Grid>
<Rectangle Fill="{TemplateBinding Background}"/>
<ContentPresenter ContentSource="Header"/>
</Grid>
<Grid>
<Rectangle Stroke="{TemplateBinding BorderBrush}"/>
<ItemsPresenter Margin="2,0,0,0"/>
</Grid>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<PathGeometry x:Key="ABC_Style">
M10.395,0.5 L30.237,0.5 30.237,5.0359993 39.499999,5.0359993 39.499999,22.75 30.237,22.75 30.237,42.660999 39.499999,42.660999 39.499999,60.375 30.237,60.375 30.237,65 10.395,65 10.395,58.124999 0.5,58.124999 0.5,10 10.395,10 z
</PathGeometry>
</Window.Resources>
<Grid>
<HeaderedItemsControl>
<HeaderedItemsControl.Header>
<Path Stroke="Black" Data="{StaticResource ABC_Style}" />
</HeaderedItemsControl.Header>
</HeaderedItemsControl>
</Grid>
</Window>
The default style for HeaderedItemsControl
doesn't normally actually include the header, for reasons beyond me. 由于我以外的原因,
HeaderedItemsControl
的默认样式通常实际上并不包含标题。 Also the way you were trying to set the header to be the path data you had wasn't right, so I fixed it by defining the PathGeometry
as a static resource and then including a Path
using that as the Header
. 同样,您尝试将标头设置为您拥有的路径数据的方法也不正确,因此我通过将
PathGeometry
定义为静态资源,然后包含使用该Header
作为Header
的Path
来修复了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.