Click here to Skip to main content
15,900,108 members
Home / Discussions / WPF
   

WPF

 
AnswerBad bad bad developer Pin
Pete O'Hanlon21-Dec-10 20:15
mvePete O'Hanlon21-Dec-10 20:15 
QuestionStrange WPF Behavior Under XP Pin
Richard Andrew x6421-Dec-10 13:33
professionalRichard Andrew x6421-Dec-10 13:33 
AnswerRe: Strange WPF Behavior Under XP Pin
SledgeHammer0121-Dec-10 13:46
SledgeHammer0121-Dec-10 13:46 
GeneralRe: Strange WPF Behavior Under XP Pin
Richard Andrew x6421-Dec-10 13:50
professionalRichard Andrew x6421-Dec-10 13:50 
Questionwindows server 2003 - silverlight 4 deployment Pin
arkiboys21-Dec-10 4:13
arkiboys21-Dec-10 4:13 
AnswerRe: windows server 2003 - silverlight 4 deployment Pin
RobCroll21-Dec-10 5:22
RobCroll21-Dec-10 5:22 
GeneralRe: windows server 2003 - silverlight 4 deployment Pin
arkiboys21-Dec-10 5:29
arkiboys21-Dec-10 5:29 
QuestionDependencyProperty Validation Question [modified] Pin
seamus_mcgowan21-Dec-10 2:55
seamus_mcgowan21-Dec-10 2:55 
I'm missing something in my understanding of how to use DP validation and probably in custom control design in general.

Here's the problem:

I've created a numeric text box, yeah another one. One feature it supports is a flag for whole number vs real number support. Another feature is Increment, where an Increment is 1 for whole numbers and 0 to 1 for real numbers.

I have implemented Validation Callbacks as:

var propertyMetadata = new FrameworkPropertyMetadata(1.0, OnIncrementChanged, OnCoerceIncrementProperty);
IncrementProperty = DependencyProperty.Register("Increment",
                                                typeof (Double),
                                                typeof (NumericTextBox),
                                                propertyMetadata,
                                                IsIncrementValid);

 public static readonly DependencyProperty IncrementProperty;

 [EditorBrowsable]
 public Double Increment
 {
     get { return (Double) GetValue(IncrementProperty); }
     set { SetValue(IncrementProperty, value); }
 }

 private static object OnCoerceIncrementProperty(DependencyObject sender, object data)
 {
     var value = (Double) data;
     var numericTextBox = (NumericTextBox) sender;

     if (numericTextBox.IsWholeNumberOnly)
     {
         return 1.0;
     }

     if (value > 0 && value <= 1)
     {
         return value;
     }

     return 1.0;
 }

 private static void OnIncrementChanged(DependencyObject obj, DependencyPropertyChangedEventArgs eventArgs){}

 // Note that this a validation for the type, not an instance!
 private static bool IsIncrementValid(object value)
 {
     var val = (Double) value;
     return val > 0 && val <= 1;
 }


My logic actually works fine, the problem is that it does not play nice with wpf. For example, in the properties window, if I set the flag for whole number and I enter .5 for the Increment the property window updates as expected, back to one (silently, without an indication I entered a bogus value). However, the XAML still shows the .5. Aside from that the logic of the control works correctly, it ignores the .5. If I type in the XAML editor I get no warning that the value is bogus. I believe this behavior is due to the logic in the coerce callback.

If I set a value in the properties window or in XAML that fails the logic of the IsIncrementValid callback, such as 2, I get a warning from both the properties window and the XAML editor and the value is never set.

Apparently the coerce validation callback is working for the properties window but not the XAML. The IsIncrementValid callback is working in the XAML and in the properties window. Of course the IsIncrementValid callback applies to the type not an instance. So the behavior I need is for IsIncrementValid to apply to instances so I can base the evaluation of validity on another instance property. In fact what I need is to be able to apply the code in the coerce callback to the isValid callback.

Any suggestions that would shed light on how to do this correctly would be appreciated.

I would also appreciate any suggestions for eliminating the plumbing code for DP's. Other then the callbacks, DP's are very much boilerplate.

Thanks in advance.

modified on Wednesday, December 22, 2010 7:30 AM

QuestionCustom client side deserialisation Pin
Adriaan Davel21-Dec-10 1:53
Adriaan Davel21-Dec-10 1:53 
QuestionCreating Flow chart elements dynamically using SilverLight Pin
Pari Margu21-Dec-10 0:40
Pari Margu21-Dec-10 0:40 
AnswerRe: Creating Flow chart elements dynamically using SilverLight Pin
#realJSOP21-Dec-10 1:34
professional#realJSOP21-Dec-10 1:34 
Questioncan not browse to my site Pin
arkiboys20-Dec-10 22:32
arkiboys20-Dec-10 22:32 
AnswerRe: can not browse to my site Pin
RobCroll21-Dec-10 4:44
RobCroll21-Dec-10 4:44 
GeneralRe: can not browse to my site Pin
arkiboys21-Dec-10 4:50
arkiboys21-Dec-10 4:50 
GeneralRe: can not browse to my site Pin
RobCroll21-Dec-10 5:17
RobCroll21-Dec-10 5:17 
GeneralRe: can not browse to my site Pin
arkiboys22-Dec-10 3:50
arkiboys22-Dec-10 3:50 
AnswerRe: can not browse to my site Pin
mbcrump12-Jan-11 4:54
mentormbcrump12-Jan-11 4:54 
QuestionFlowchart control Pin
devvvy20-Dec-10 22:01
devvvy20-Dec-10 22:01 
AnswerRe: Flowchart control Pin
Pete O'Hanlon20-Dec-10 22:11
mvePete O'Hanlon20-Dec-10 22:11 
AnswerRe: Flowchart control Pin
Abhinav S20-Dec-10 22:35
Abhinav S20-Dec-10 22:35 
QuestionCreate XML from Silverlight DataGrid Pin
Member-495917620-Dec-10 17:47
Member-495917620-Dec-10 17:47 
AnswerRe: Create XML from Silverlight DataGrid Pin
RaviRanjanKr20-Dec-10 18:06
professionalRaviRanjanKr20-Dec-10 18:06 
AnswerRe: Create XML from Silverlight DataGrid Pin
Mycroft Holmes20-Dec-10 20:52
professionalMycroft Holmes20-Dec-10 20:52 
AnswerRe: Create XML from Silverlight DataGrid Pin
Pete O'Hanlon20-Dec-10 22:09
mvePete O'Hanlon20-Dec-10 22:09 
QuestionDeployment Pin
arkiboys20-Dec-10 4:25
arkiboys20-Dec-10 4:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.