2008-12-12 27 views
1

我的目標是製作一個具有兩個內容值的按鈕。如何製作具有多個內容值的按鈕?

想象一下Scrabble瓷磚作爲一個按鈕:它的中心有一個大字母,右下方有一個小字母。這是我要去的效果。

我做了一個按鈕,它有兩個ContentPresenter對象,並且我給每個ContentPresenter一個不同的樣式。但是,我還沒有找到給每個演示者一個單獨的值的方法(即,如果我將按鈕的內容設置爲「X」,則兩個ContentPresenter都顯示「X」,儘管樣式不同)。

我該如何實現我的目標?我猜我的做法是完全錯誤的......

回答

2

巴...我想我知道現在要做什麼。我應該讓自己的控制,而不是修改一個按鈕。如果我在WinForms中工作,這對我來說是顯而易見的,但由於某種原因,所有這些Xaml都讓我變得愚蠢。

1

看一看擴展器樣品的ControlTemplate在http://msdn.microsoft.com/en-us/library/ms753296.aspx

擴展是HeaderedContentControl的一個子類,它有兩個「內容」:報頭和內容

控制模板具有兩個ContentPresenter元件時,ContentPresenter那未綁定到默認內容屬性被定義爲:

< ContentPresenter ContentSource = 「部首」/ >

如果您需要使用按鈕,並且不想爲第二個內容添加其他屬性,則可以使用附加屬性,並將數據綁定到第二個ContentPresnter內容屬性。

0

我使用多個'內容槽'創建UserControl延遲here - 它比從HeaderedControl派生的更好,因爲您不受插槽數量的限制。

使用範例:

<Window x:Class="TkMVVMContainersSample.Services.TaskEditDialog.ItemEditView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:Common="clr-namespace:TkMVVMContainersSample.Views.Common" 
    Title="ItemEditView" 
    > 
    <Common:DialogControl> 
     <Common:DialogControl.Heading> 
      <!-- Heading string goes here --> 
     </Common:DialogControl.Heading> 
     <Common:DialogControl.Control> 
      <!-- Concrete dialog's content goes here --> 
     </Common:DialogControl.Control> 
     <Common:DialogControl.Buttons> 
      <!-- Concrete dialog's buttons go here --> 
     </Common:DialogControl.Buttons> 
    </Common:DialogControl> 

</Window> 
相關問題