2012-02-03 53 views
-1

好吧,我覺得我使用ControlTemplate哈哈...請教我如何正確使用ControlTemplate? (有人刪除請)

我想要的是模板我的每個用戶控件,因此每個用戶控件將有刪除,保存,取消按鈕。

所以現在我書面方式一些測試...... 儘量讓周圍的一切邊界...

在App.xaml中

<Application.Resources> 
    <ControlTemplate x:Key="DeleteSaveCancelTemplate"> 
     <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> 
      <Border BorderThickness="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Black"> 
       <ContentPresenter/> 
      </Border> 
     </Grid> 
    </ControlTemplate> 
</Application.Resources> 

然後在用戶控件:

<UserControl ... Height="150" Width="300" Template="{StaticResource DeleteSaveCancelTemplate}" > 

但我看到的只是......黑色......我做錯了什麼?我以爲我應該使用ContentPresenter來顯示內容?

回答

0

所以......我默認情況下,發現了這個問題笑從this pageControlPresenter好好嘗試一下結合到內容...... 我需要寫

<ContentPresenter Content="{TemplateBinding Property=ContentControl.Content}" /> 

除非你有指定的TargetType,那麼你會默認綁定它。

0

對於大多數使用ContentPresenter的控件。 ItemsPresenter僅適用於擴展ItemsControl的元素。

+0

我剛剛意識到這一點,我也嘗試使用ContentPresenter,但它並沒有工作.. – 2012-02-03 21:10:48