2011-09-09 159 views
0

我正在創建一個自定義Silverlight按鈕。由於我想獲得視覺狀態,我不想使用樣式或控件模板。所以,我寫這樣的:在不使用樣式的情況下在Silverlight中創建自定義按鈕

<Button x:Class="MyNameSpace.MyImageButton" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

<Grid x:name="LayoutRoot"> 
    <VisualStateManager.VisualStateGroups> 
    <VisualStateGroup ... 

    </VisualStateGroup> 
    <VisualStateManager.VisualStateGroups> 
    <Border (Various border styles) 
<StackPanel x:Name="ContentPresenter" Orientation="Horizontal"> 
       <Image Source="{Binding Path=this.ImageSource}" Stretch="Fill" /> 
       <!--ContentPresenter--> 
       <ContentPresenter HorizontalAlignment="{Binding Path=this.HorizontalContentAlignment}" 
                 VerticalAlignment="{Binding Path=this.VerticalContentAlignment}" > 
         <TextBlock Text="{Binding Path=this.Content}" /> 
       </ContentPresenter> 

      </StackPanel> 
    </Border> 
</Grid> 
<Button.BorderBrush> 
..... 
<Button.BorderBrush> 
</Button> 

但是造型似乎並不奏效。它顯示默認的按鈕樣式。如何使它工作。我還註冊了一個圖像源屬性。這似乎也不起作用。

請幫忙。提前致謝。

回答

0

實際上,在Silverlight 4中,如果您使用的是按鈕,則不能沒有樣式。我嘗試了很多。即使我試圖給我在Button中聲明的邊框添加一些顏色。最後,我使用從UserControl派生的獨立控件。這對我幫助很大。當然它不給我一個按鈕的靈活性,但它給了我想要的東西。我現在可以直接從控件中選擇視覺狀態。

+0

如果您有任何關於此的信息,請對此評論。 –

相關問題