using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.ComponentModel; using System.Windows.Markup; namespace CustomControls { /// /// Interaction logic for RequiredLabel.xaml /// [ContentProperty("Text")] public partial class RequiredLabel : UserControl { public RequiredLabel() { InitializeComponent(); } static RequiredLabel() { //DefaultStyleKeyProperty.OverrideMetadata(typeof(RequiredLabel), new FrameworkPropertyMetadata(typeof(RequiredLabel))); TextProperty = DependencyProperty.Register( "Text", typeof(string), typeof(RequiredLabel), new FrameworkPropertyMetadata( new PropertyChangedCallback(OnTextChanged))); LabelStyleProperty = DependencyProperty.Register( "Style", typeof(Style), typeof(RequiredLabel), new FrameworkPropertyMetadata( new PropertyChangedCallback(OnStyleChanged))); } public static DependencyProperty TextProperty; [Category("Common Properties"), Bindable(true)] public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } private static void OnTextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { ((RequiredLabel)sender).txtBlock.Text = e.NewValue.ToString(); } public static DependencyProperty LabelStyleProperty; public new Style Style { get { return (Style)GetValue(LabelStyleProperty); } set { SetValue(LabelStyleProperty, value); } } private static void OnStyleChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { ((RequiredLabel)sender).lblMain.Style = (Style)e.NewValue; } } }