自定义WPF GroupBox中包含的命名控件

问题描述

| 我有一个自定义的GroupBox控件,该控件实际上只不过是应用样式
<GroupBox x:Class=\"SharedResources.Controls.StyledGroupBox\"
          xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"
          xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">
    <GroupBox.Style>
        <Style TargetType=\"{x:Type GroupBox}\">
            <Setter Property=\"BorderBrush\" Value=\"#D5DFE5\"/>
            <Setter Property=\"BorderThickness\" Value=\"1\"/>
            <Setter Property=\"Template\">
                <Setter.Value>
                    <ControlTemplate TargetType=\"{x:Type GroupBox}\">
                        ...
                            <ContentPresenter Grid.ColumnSpan=\"2\" Grid.Column=\"1\" Grid.Row=\"2\" 
                                              Margin=\"{TemplateBinding Padding}\" 
                                              SnapsToDevicePixels=\"{TemplateBinding SnapsToDevicePixels}\"/>

                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </GroupBox.Style>
</GroupBox>
问题是,当我开始使用它时,如果我设置了StyledGroupBox的内容的x:Name属性,则会出现以下错误: 无法在元素\'\'上设置名称属性值\'name \'。 \'\'在元素\'StyledGroupBox \'的范围内,该元素在另一个范围中定义时已经注册了名称 有什么想法可以解决这个问题吗?     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)