Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - [WPF] data binding and SetValue()

 
 
Old 06-15-2007   #1 (permalink)
Lloyd Dupont


 
 

[WPF] data binding and SetValue()

I have a color chooser class
class ColorPicker : Control
{
public byte R { get; set; }
public byte G { get; set; }
public byte B { get; set; }
public Color Color { get; set; }
}

All are dependency properties.
All these dependency properties are obviously related, when Red change,
Color change and vice versa.

Now I wonder how to update them as a whole.

If I do it directly mysefl as in:
When R change I call SetValue(ColorProperty, newValue)
That feel wrong.

Because if the user call, let's say:
ClearValue(ColorProperty) I end up calling SetValue(RProperty, ..), while I
should in fact clear it...

does it makes sense?
How should I synchronize values?


My System SpecsSystem Spec
Old 06-15-2007   #2 (permalink)
Nicholas Paldino [.NET/C# MVP]


 
 

Re: [WPF] data binding and SetValue()

Lloyd,

Are you attaching an event handler to the DependencyProperty instance
for when those values change? You should be able to set event handlers for
each of them (or rather, one for the R, G, B, values, and one for the Color
value) and then modify the values in the event handler. When you call
SetValue from the event handler, it should prevent the setting of the values
from triggering the respective change events, and subsequently, an endless
loop.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"Lloyd Dupont" <net.galador@ld> wrote in message
news:uPdO8rxrHHA.1296@TK2MSFTNGP06.phx.gbl...
>I have a color chooser class
> class ColorPicker : Control
> {
> public byte R { get; set; }
> public byte G { get; set; }
> public byte B { get; set; }
> public Color Color { get; set; }
> }
>
> All are dependency properties.
> All these dependency properties are obviously related, when Red change,
> Color change and vice versa.
>
> Now I wonder how to update them as a whole.
>
> If I do it directly mysefl as in:
> When R change I call SetValue(ColorProperty, newValue)
> That feel wrong.
>
> Because if the user call, let's say:
> ClearValue(ColorProperty) I end up calling SetValue(RProperty, ..), while
> I should in fact clear it...
>
> does it makes sense?
> How should I synchronize values?



My System SpecsSystem Spec
Old 06-16-2007   #3 (permalink)
Lloyd Dupont


 
 

Re: [WPF] data binding and SetValue()

Hi Nicholas,

My worry are not from endless loop which I know how to prevent, but more
from other problem which I'm not sure it's even relevant...
(the fact that I'm calling SetValue() sometime when ClearValue() would be
more appropriate)

--
Regards,
Lloyd Dupont
NovaMind Software
Mind Mapping at its best
www.nova-mind.com
"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in
message news:u2gXYN3rHHA.3432@TK2MSFTNGP02.phx.gbl...
> Lloyd,
>
> Are you attaching an event handler to the DependencyProperty instance
> for when those values change? You should be able to set event handlers
> for each of them (or rather, one for the R, G, B, values, and one for the
> Color value) and then modify the values in the event handler. When you
> call SetValue from the event handler, it should prevent the setting of the
> values from triggering the respective change events, and subsequently, an
> endless loop.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - mvp@spam.guard.caspershouse.com
>
> "Lloyd Dupont" <net.galador@ld> wrote in message
> news:uPdO8rxrHHA.1296@TK2MSFTNGP06.phx.gbl...
>>I have a color chooser class
>> class ColorPicker : Control
>> {
>> public byte R { get; set; }
>> public byte G { get; set; }
>> public byte B { get; set; }
>> public Color Color { get; set; }
>> }
>>
>> All are dependency properties.
>> All these dependency properties are obviously related, when Red change,
>> Color change and vice versa.
>>
>> Now I wonder how to update them as a whole.
>>
>> If I do it directly mysefl as in:
>> When R change I call SetValue(ColorProperty, newValue)
>> That feel wrong.
>>
>> Because if the user call, let's say:
>> ClearValue(ColorProperty) I end up calling SetValue(RProperty, ..), while
>> I should in fact clear it...
>>
>> does it makes sense?
>> How should I synchronize values?

>
>


My System SpecsSystem Spec
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46