2010-07-06 31 views
8

Bu sabah WPF'ye başladım, böylece bu (umarız) çözülmesi kolay bir soru. Degrade arka planı olan bir düğme oluşturmaya başladım. Kontrolün özelliklerinde degrade başlangıç ​​ve bitiş renklerini bildirmek ve bunları şablonda uygulamak istiyorum. Yine de kodu derlemek için sorun yaşıyorum. Ben alıyorum istisna ben xaml özelliği erişilebilir değil halka açık üzerinden görünürlüğü değiştirici söylüyorum ama bu statik özelliği bulamadığı için şikayet olduğunu ...Özel WPF Denetimi'ne Özellikler Ekleme?

Şimdiye kadar benim xaml İşte :

<StackPanel> 
    <StackPanel.Resources> 
     <Style TargetType="my:GradientButton"> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type my:GradientButton}"> 
         <Grid> 
          <Ellipse Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Stroke="{TemplateBinding Foreground}" VerticalAlignment="Top" HorizontalAlignment="Left"> 
           <Ellipse.Fill> 
            <LinearGradientBrush> 
             <GradientStop Color="{TemplateBinding GradientStart}" Offset="0"></GradientStop><!--Problem on this line!!!--> 
             <GradientStop Color="{TemplateBinding GradientEnd}" Offset="1"></GradientStop> 
            </LinearGradientBrush> 
           </Ellipse.Fill> 
          </Ellipse> 
          <Polygon Points="18,12 18,38, 35,25" Fill="{TemplateBinding Foreground}" /> 
         </Grid> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </StackPanel.Resources> 
    <my:GradientButton x:Name="btnPlay" Height="50" Width="50" Foreground="Black" Click="Button_Click" GradientStart="#CCCCCC" GradientEnd="#7777777" /> 
</StackPanel> 

Ve burada benim özel denetim için kod:

public class GradientButton : Button 
{ 
    static DependencyProperty GradientStartProperty; 
    static DependencyProperty GradientEndProperty; 

    static GradientButton() 
    { 
     GradientStartProperty = DependencyProperty.Register("GradientStart", typeof(Color), typeof(GradientButton)); 
     GradientEndProperty = DependencyProperty.Register("GradientEnd", typeof(Color), typeof(GradientButton)); 
    } 

    public Color GradientStart 
    { 
     get { return (Color)base.GetValue(GradientStartProperty); } 
     set { base.SetValue(GradientStartProperty, value); } 
    } 

    public Color GradientEnd 
    { 
     get { return (Color)base.GetValue(GradientEndProperty); } 
     set { base.SetValue(GradientEndProperty, value); } 
    } 
} 

DÜZENLEME: İşte

alıyorum tasarım zamanı istisna

cevap

9

olayı çözdüm ... Bu: Gereken

static DependencyProperty GradientStartProperty; 
static DependencyProperty GradientEndProperty; 

bu şekilde değiştirilmesi:

public static DependencyProperty GradientStartProperty; 
public static DependencyProperty GradientEndProperty; 
İlgili konular