![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | [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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| Thread Tools | |
| |