2016-12-20 18 views
0

WPFでカスタムボタンを行いました。スタイルに合わせていくつかのプロパティを追加しました。しかし、いくつかのものは正しく動作しません。カスタムボタンWPFはプロパティをバインドしません

コントロール。画像、テキストが正しく表示され

public class CustomButton : Button 
{ 
    public static readonly DependencyProperty TextProperty; 
    public static readonly DependencyProperty ImageProperty; 
    public static readonly DependencyProperty ImageRollvoerProperty; 
    public static readonly DependencyProperty TextMarginProperty; 

    static CustomButton() 
    { 
     TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(CustomButton), new UIPropertyMetadata(null)); 
     ImageProperty = DependencyProperty.Register("Image", typeof(ImageSource), typeof(CustomButton), new UIPropertyMetadata(null)); 
     ImageProperty = DependencyProperty.Register("ImageRollvoer", typeof(ImageSource), typeof(CustomButton), new UIPropertyMetadata(null)); 
     TextMarginProperty = DependencyProperty.Register("TextMargin", typeof(string), typeof(CustomButton), new UIPropertyMetadata(null)); 
    } 

    public string Text 
    { 
     get { return (string)GetValue(TextProperty); } 
     set { SetValue(TextProperty, value); } 
    } 

    public ImageSource Image 
    { 
     get { return (ImageSource)GetValue(ImageProperty); } 
     set { SetValue(ImageProperty, value); } 
    } 

    public ImageSource ImageImageRollvoer 
    { 
     get { return (ImageSource)GetValue(ImageRollvoerProperty); } 
     set { SetValue(ImageRollvoerProperty, value); } 
    } 

    public string TextMargin 
    { 
     get { return (string)GetValue(TextMarginProperty); } 
     set { SetValue(TextMarginProperty, value); } 
    } 
} 

スタイル

<Setter.Value> 
    <ControlTemplate TargetType="{x:Type local:XposButton}"> 
     <Grid ClipToBounds="True"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="{TemplateBinding Height}" /> 
       <RowDefinition Height="Auto"/> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="{TemplateBinding Width}" /> 
      </Grid.ColumnDefinitions> 
      <local:ClippingBorder Grid.Row="0" Grid.Column="0" BorderThickness="0" CornerRadius="10" Background="{StaticResource OxxoMetroBackground}" BorderBrush="{StaticResource OxxoMetroBorder}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"> 
       <local:ClippingBorder Background="{StaticResource OxxoMetroBackground}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="2" CornerRadius="9"> 
        <local:ClippingBorder x:Name="Overlay" ClipToBounds="True" Background="Transparent" BorderBrush="{StaticResource OxxoMetroBorder}" BorderThickness="0"> 
         <Image Name="btnImage" Source="{TemplateBinding Image}" Style="{StaticResource ImageUninhabitable}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" /> 
        </local:ClippingBorder> 
       </local:ClippingBorder> 
      </local:ClippingBorder> 
      <TextBlock Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" Margin="{TemplateBinding TextMargin}" Text="{TemplateBinding Text}" Style="{DynamicResource TextBlockMenuImg}" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}"/> 
     </Grid> 
    </ControlTemplate> 
</Setter.Value> 

ビュー

<ctrl:CustomButton FontFamily="Roboto" Margin="17" TextMargin="0,20,0,0" Width="150" Image="{Binding Path=ImageUrl}" Text="{Binding ShowName}" x:Name="btnMenu" Style="{StaticResource CustomButtonStyle}" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}, Path= DataContext.SelectMenuCommand}" CommandParameter="{Binding}" /> 

、のfontFamily、およびTextMarginが正しく動作しません。

+0

私が推測しなければならないのであれば、 'TextMargin'は文字列ではありません。 – BradleyDotNET

+0

私はこれをスタイル の 'Margin =" {Binding RelativeSource = {RelativeSource TemplatedParent}、Path = TextMargin} "'とマージンワークスに入れました。私はFontFamilyがなぜdo notを見つけるのを続ける – user3582756

+0

埋め込まれたフォントの問題かもしれませんか?デフォルトフォントの1つを試してみてください...それは私の推測です – Yitzchak

答えて

0

プロパティがStringではなくThickness型として定義される必要があるため、Marginのバインディングはおそらく機能していません。

public Thickness TextMargin 
関連する問題