Domanda

I try to give my ControlTemplate of the type Button some DependencyProperties. For that, I made a class called "ControlButton" and inherited it from Button. I gave this class an empty constructor and tried to connect this class with the style that contains the ControlTemplate.

Here's my Style that contains the ControlTemplate:

<Style
    TargetType="{x:Type local:ControlButton}"
    x:Key="ControlButton"
    xmlns:local="clr-namespace:FileZip">
    <Setter
        Property="Template">
        <Setter.Value>
            <ControlTemplate
                TargetType="{x:Type local:ControlButton}">
                <Border>
                    <!-- ... -->
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Here is my class that should help me to add some DependencyProperties. I didn't add DependencyProperties, because I wanted to see if the connection between class and style works:

namespace FileZip {
    public partial class ControlButton : Button {
        public ControlButton () : base() {}
    }
}

With following code I tried to use my ControlButton

<StackPanel
    xmlns:local="clr-namespace:FileZip">
    <local:ControlButton
        Content="X" />
</StackPanel>

Everytime I try to compile my code, Visual Studio returns following two errors:

  • "The name 'ControlButton' doesn't exist in the namespace 'FileZip'"
  • "Missing XmlNamespace, Assembly, or ClrNamespace in Mapping instruction"

Thanks in advance for your help.

I'm sorry, if my English isn't very good.

È stato utile?

Soluzione

Read the section explaining how to apply styles to custom control. Also read the section exampling how to use external assemblies.

http://msdn.microsoft.com/en-us/library/cc295235.aspx

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top