Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Custom Control dependency property doesnt called

$
0
0

Hello,

I'm having Custom button control which is derived from Button Control,

Code Snippet:

   public class CustomButton : Button
    {
        public  CustomButton()
        {

        }

        public Brush BackGroundButton
        {
            get { return (Brush)GetValue(BackGroundButtonProperty); }
            set { SetValue(BackGroundButtonProperty, value); }
        }

        // Using a DependencyProperty as the backing store for BackGroundButton.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty BackGroundButtonProperty =
            DependencyProperty.Register("BackGroundButton", typeof(Brush), typeof(CustomButton), new PropertyMetadata(new SolidColorBrush(Colors.Black)));


        public Brush ForeGroundButton
        {
            get { return (Brush)GetValue(ForeGroundButtonProperty); }
            set { SetValue(ForeGroundButtonProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ForeGroundButton.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ForeGroundButtonProperty =
            DependencyProperty.Register("ForeGroundButton", typeof(Brush), typeof(CustomButton), new PropertyMetadata(new SolidColorBrush(Colors.White)));



        private Brush btnColor =new SolidColorBrush(Colors.Red);

        public Brush BtnColor
        {
            get { return btnColor; }
            set { btnColor = value; }
        }
        private Brush bgColor =new SolidColorBrush(Colors.Pink);

        public Brush BgColor
        {
            get { return bgColor; }
            set { bgColor = value; }
        }

        //public override void OnApplyTemplate()
        //{
        //    //base.Foreground = BgColor;
        //    //base.Background = BtnColor;

        //  //  base.Content = "Button";
        //   base.OnApplyTemplate();
        //}
    }

Xaml:

<local:CustomButton Grid.Column="1"
                   Content="Button1"
                   BackGroundButton="{Binding BgColor}" ForeGroundButton="{Binding BtnColor}" /> 

Can any one help me to trigger the dependency property for CustomButton?

Regards,
jayapradha


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>