473,549 Members | 5,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WPF DependencyPrope rty Validation Binding fails

EARNEST
128 New Member
0 down vote favorite


I am trying to create a validation rule for a given control (in this scenario, it is the TextBox).

I am not able to obtain a successful Binding to the property of an object, although appropriate steps were taken: ValidationRule and DepedencyProper ty are taken advantage of.

Kindly find code below. A side note is that "Is Required" in the custom Validation class is always False, unless I explicitly set the value in the XAML (no Binding, as per "Is Ranged" parameter).

Alternative is to use IDataErrorInfo interface, but I would like to stick to the ValidationRules .

Any tips and suggestions are appreciated.

Thank you in advance :)


XAML Code:

Expand|Select|Wrap|Line Numbers
  1. <TextBox Style="{StaticResource ValidationError}" LostFocus="ForceValidationCheck"
  2.          Visibility="{Binding Type, Converter={StaticResource Visibility}, ConverterParameter='Number'}"
  3.          IsEnabled="{Binding RelativeSource={x:Static RelativeSource.Self}, Converter={StaticResource IsEnabled}}">
  4.     <TextBox.Text>
  5.         <Binding Path="Value">
  6.             <Binding.ValidationRules>
  7.                 <validation:NumericValidation>
  8.                     <validation:NumericValidation.Dependency>
  9.                         <validation:NumericDependency IsRequired="{Binding Path=IsRequired}" IsRanged="True" Min="5"/>
  10.                     </validation:NumericValidation.Dependency>
  11.                 </validation:NumericValidation>
  12.             </Binding.ValidationRules>
  13.         </Binding>
  14.     </TextBox.Text>
  15. </TextBox>
  16.  
Validation Class:

Expand|Select|Wrap|Line Numbers
  1. public NumericDependency Dependency { get; set; }
  2.  
  3. public override ValidationResult Validate(object value, CultureInfo cultureInfo)
  4. {
  5.     isRequired = Dependency.IsRequired;
  6. }
  7.  
Validation Dependency Class:

Expand|Select|Wrap|Line Numbers
  1. public static readonly DependencyProperty IsRequiredProperty =
  2.         DependencyProperty.Register("IsRequired", typeof(bool), typeof(NumericDependency), new UIPropertyMetadata(default(bool)));
  3.  
  4. public bool IsRequired
  5. {
  6.     get
  7.     {
  8.         return (bool) GetValue(IsRequiredProperty);
  9.     }
  10.     set
  11.     {
  12.         SetValue(IsRequiredProperty, value);
  13.     }
  14. }
  15.  
Dec 6 '12 #1
0 1978

Sign in to post your reply or Sign up for a free account.

Similar topics

1
281
by: Marcin Floryan | last post by:
Hello! My question regards opening (and re-opening) Form and the Load event. I have a main form (frmMain) and I also have a data form (frmData). In the main form I have created: Private fData as new frmData()
4
2619
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a script that validates the form fields. the validation procedure is called ONCLICK event of the submit button. Follwowing is the structure of the...
2
1720
by: Danny | last post by:
I created a function to test to see if entered text has a '.' in it, The code seems to work but the validation always fails even when 'true' is returned. i put = myfunction in the validation rule and ny validation messages always displays. What am I doing wrong
5
3230
by: Chris | last post by:
Based upon some prevoius postings on what to do for adding a 'add' row to a datagrid I utilize the footer to create the 'add' row. The only issue is that I have it sharing the 'UpDate_Command' and I use an argument to difference between an 'edit' vs. and 'add. But since I have field validation on both 'footer' and 'edit' columns I can't submit...
7
10264
by: christian.eickhoff | last post by:
Hi Everyone, I am currently implementing an XercesDOMParser to parse an XML file and to validate this file against its XSD Schema file which are both located on my local HD drive. For this purpose I set the corresponding XercesDOMParser feature as shown in the upcoming subsection of my code. As far as I understand, the parsing process...
2
3690
by: kogrover | last post by:
ISSUE: COM Excel Sort works with Early Binding, but not Late Binding, but py2exe only does Late Binding I have code similar to this (type from notes, so there may be a typo...) import win32com.client xl = win32com.client.Dispatch("Excel.Application") xl.Visible = False xl.ScreenUpdating = False
4
999
by: Morten Snedker | last post by:
http://test.planprojekt.dk/vaerk.aspx (http://validator.w3.org/check?uri=http%3A%2F%2Ftest.planprojekt.dk%2Fvaerk.aspx) fails validation. It fails due to tags not being closed properly. However, the failing code is produced dynamically and is regarding a couple of listboxes. Is there any way for me to get around this failing code? ...
2
6732
by: John Smith | last post by:
Hello, I have a VB.NET application with a Windows form that have several textboxes fields where I have dates entered. I would like to do a date validation check after the the field is updated, so I' using the leave event. Right now I am creating a 'leave' sub for each of the fields. However, I'd like to simplify that and just call the name...
0
995
by: shekaranjanappa | last post by:
Hi I have a requirement to do follwing operation in looop 1. open socket 2. start 3. bind 4. listion 5. close socket Here used ip address and port is same always.
7
7983
by: Some Bloke | last post by:
I am trying to bind a WPF dependency property to an aggregate of a collection. I've implemented a wrapper around a Dictionary that implements INotifyCollectionChanged to fire the event when items are added or removed. Debugging through it I notice that there is nothing listening to the event after I bind to it which I expected the...
0
7526
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7455
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7814
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5373
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.