Creating an image+text button with a control template?

后端 未结 1 1296
灰色年华
灰色年华 2020-11-30 04:57

I am tired of creating the same image+text button over and over again, and I would like to move the markup to a control template. Here is my problem: I need to provide templ

1条回答
  •  猫巷女王i
    2020-11-30 05:58

    Define a CustomControl like this

    in .cs

    public class MyButton : Button
    {
        static MyButton()
        {
           //set DefaultStyleKeyProperty
        }   
    
        public ImageSource ImageSource
        {
            get { return (ImageSource)GetValue(ImageSourceProperty); }
            set { SetValue(ImageSourceProperty, value); }
        }
    
        // Using a DependencyProperty as the backing store for ImageSource.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ImageSourceProperty =
            DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(MyButton), new UIPropertyMetadata(null));
    }
    

    in generic.xaml of themes folder

    
    

    0 讨论(0)
提交回复
热议问题