2013-10-13 43 views
0

我嘗試給我的ControlTemplate的類型Button一些DependencyProperties。爲此,我創建了一個名爲「ControlButton」的類並從Button繼承它。我給這個類一個空的構造函數,並試圖將這個類與包含ControlTemplate的樣式連接起來。WPF - ControlTemplate自定義DependencyProperties

這裏是我的風格包含控件模板:

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

這裏是我,應該幫助我增加一些DependencyProperties。我沒加DependencyProperties,因爲我想看看是否類和風格之間的連接工作:

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

有了下面的代碼我試圖用我的ControlButton

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

每次我嘗試編譯我的碼,下面的兩個錯誤的Visual Studio的回報:

  • 「 'ControlButton' 這個名字不會在命名空間存在 'FileZip'」
  • 「在映射指令中缺少XmlNamespace,Assembly或ClrNamespace」

在此先感謝您的幫助。

對不起,如果我的英語不太好。

+0

你'xmlns'聲明應該在XAML的頂部。不在控制層面。 – Tico

+0

'FileZip'與您的'XAML'駐留在相同的程序集中,還是處於不同的程序集中? –

+0

目前只有一個名爲FileZip的名稱空間。這也是組件的名稱。 – Cubinator73

回答