KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am not sure why the validation state doesn't get reflected in my user control. I am throwing an exception but for some reason the control doesn't show the validation state...When I use a standard Textbox (Which is commented out right now in my example) on my MainPage it shows the error state, not sure why its not when its wrapped. I have slimmed this down so basically its a user control that wraps a TextBox . What am I missing?? MyUserControl XAML: <UserControl x:Class="ValidationWithUserControl.MyUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <TextBox x:Name="TextBox"/> </Grid> </UserControl> MyUserControl Code Behind: public partial class MyUserControl : UserControl { public MyUserControl() { InitializeComponent(); this.Loaded += new RoutedEventHandler(MyUserControl_Loaded); this.TextBox.Unloaded += new RoutedEventHandler(TextBox_Unloaded); } public string Value { get { return (string)base.GetValue(ValueProperty); } set { base.SetValue(ValueProperty, value); } } public static DependencyProperty ValueProperty = DependencyProperty.Register( "Value", typeof(string), typeof(MyUserControl), new PropertyMetadata(null)); private void MyUserControl_Loaded(object sender, RoutedEventArgs e) { this.TextBox.SetBinding(TextBox.TextProperty, new Binding() { Source = this, Path = new PropertyPath("Value"), Mode = BindingMode.Two
Tags (comma-separated)
Save Edits
Cancel