![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | TwoWay DataBinding to property having private set Is it possible to make TwoWay DataBinding to property having private set Below is the code of BindingObject class that has property Name whose Get is public but Set is private but there is one Public method in this class SetProperty which can be called to set value of Name property. So my requirement is to make TwoWay DataBinding with this property. Is there any workaround that binding can call SetProperty rather calling Set of Name property //Business Object Code public class BindingObject : INotifyPropertyChanged { string name; public BindingObject() { this.name = "WPF"; } public string Name { get { return this.name; } private set { this.name = value; if (PropertyChanged!=null) { PropertyChanged(this, new PropertyChangedEventArgs("Name")); } } } public void SetProperty(string value) { this.name = value; } } //GUI Code InitializeGUI() { TextBox textBox = new TextBox(); Binding binding = new Binding("Name"); binding.Source = new BindingObject(); binding.Mode = BindingMode.TwoWay; textBox.SetBinding(TextBox.TextProperty, binding);//throws exception as Name property has private set } Thanks Gaurav |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: TwoWay DataBinding to property having private set Since you have a private 'set', every attempt to set the variable will fail, wetherver your are using databinding or not. I think the only way you can databind an object with private set accessor is using oneway databinding (from the BindingObject to the TextBox.Text) since there is no way for the TextBox to set the Name property. On Feb 26, 11:48 pm, gauravgoyal.a...@xxxxxx wrote:
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||
| Guest | Re: TwoWay DataBinding to property having private set there is one public method SetProperty() which can be used to set Name property. So is there any way that .Net make call to this function rather then set of Name property Gaurav On Feb 27, 3:28*am, BladeWise <dany2...@xxxxxx> wrote:
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||
| Guest | Re: TwoWay DataBinding to property having private set On Feb 27, 3:27 pm, gauravgoyal.a...@xxxxxx wrote:
more than one parameter to set that value, otherwise there would be no need of a SetName function; unfortunally DependencyProperties, as far as I know, rely on a simple get/set with a single parameter. | ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #5 (permalink) | ||||||||||||||||||||||||
| Guest | Re: TwoWay DataBinding to property having private set Before TwoWay DataBindings is established each side of the binding (dependency property) is checked to be writeable and so having a setter. This means that an exception will be raised in your case and no binding will be established. And this is fair enough. If you are intrested in binding to readonly property than you should move on to OneWay binding that perfectly suites your schema. "gauravgoyal.aqua@xxxxxx" wrote:
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Use my custom TypeDescriptor to obtains default Value on property inXAML Property Editor of Visual Studio 2008 | azerty | Avalon | 0 | 04-14-2008 06:14 AM |
| WPF: Autogenerate a Private Dependency Property ? | Jules Winfield | .NET General | 4 | 03-06-2008 09:43 AM |
| Private Network becomes Public on reboot and I want it as Private. | Jon | Vista networking & sharing | 5 | 01-08-2008 09:59 AM |
| Bug about TwoWay DataBinding & Coerce function | HolaMan | Avalon | 0 | 11-21-2006 03:14 AM |
| Animating databinding changes ? | jods | Avalon | 4 | 06-20-2006 03:21 PM |