C# 路径和XAML控件

C# 路径和XAML控件,c#,wpf,xaml,C#,Wpf,Xaml,为了在工具箱上显示对象并允许用户将其拖放到画布上,我使用以下控件: <HeaderedItemsControl x:Key="itemABC" Width="100" Height="100" Canvas.Left="210" Canvas.Top="220" Margin="0,0,0,0" S

为了在工具箱上显示对象并允许用户将其拖放到画布上,我使用以下控件:

<HeaderedItemsControl x:Key="itemABC" 
                Width="100"
                Height="100"
                Canvas.Left="210"
                Canvas.Top="220"
                Margin="0,0,0,0"
                Style="{StaticResource ABC_Style}">

</HeaderedItemsControl>

在风格上定义了:

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

但是,问题是HeaderItemsControl没有路径属性(据我所知),所以我想知道这里还有什么其他选项

事实上,我需要在XAML中显示HeaderedItemsControl内部的路径

谢谢。

此示例适用于:

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

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,65 10.395,65 10.395,58.124999 0.5,58.124999 0.5,10.395,10 z

HeaderedItemsControl
的默认样式通常不包含标题,原因超出我的理解。另外,您试图将标头设置为路径数据的方式也不正确,因此,我将
PathGeometry
定义为一个静态资源,然后包含一个
Path
,并将其用作
Header

您可能应该将
Header
属性设置为一个
Path
对象,并将其作为其数据属性。如果这是解决方案,让我知道,我会给你一个答案。如果你的意思是改变“数据”为“标题”,那么我累了,但没有影响它。它运行良好,但没有内容。谢谢,由于给定的设计,我在中使用了两个模块。在这种情况下应该做些什么改变?谢谢你用你给我的相同技术和XAML中的一些小调整使它工作起来。非常感谢。