dynamic modify property of control
-
Hi, I have couple of controls in canvas and a single text box, which shows the width property of selected controls in canvas. Now if i select any control in canvas it should reflect its width in textbox, and i should also be able to edit the width, which gets reflected back to the selected contorl. Just like the property window in blend. There are property grid controls, but they are too complicated for me, and i just want one property in text box. I have tried two way bindings programatically, but doesnt work properly. Is there any simple way to implement this
-
Hi, I have couple of controls in canvas and a single text box, which shows the width property of selected controls in canvas. Now if i select any control in canvas it should reflect its width in textbox, and i should also be able to edit the width, which gets reflected back to the selected contorl. Just like the property window in blend. There are property grid controls, but they are too complicated for me, and i just want one property in text box. I have tried two way bindings programatically, but doesnt work properly. Is there any simple way to implement this
DeepakMega wrote:
I have tried two way bindings programatically, but doesnt work properly.
What did you try? If you want to bind the selected control's Width property to the TextBox.Text, then you'll (probably) need a converter on your binding that converts a string to a double.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
DeepakMega wrote:
I have tried two way bindings programatically, but doesnt work properly.
What did you try? If you want to bind the selected control's Width property to the TextBox.Text, then you'll (probably) need a converter on your binding that converts a string to a double.
Mark Salsbery Microsoft MVP - Visual C++ :java:
The controls are dynamically added to the canvas. And when a control is selected by mouse, its fontsize property is shown in the textbox. So i tried to bind the controls fontsize to the textbox // here im trying to bind the controls fontsize property to the textbox (txtFontsize) // this code runs when an control is selected unbind(); //this unbinds any control in canvas binded to the textbox myBinding = new Binding("Text"); myBinding.Source = txtFontsize; // txtFontSize is the textbox which shows the selected control property myBinding.Mode = BindingMode.TwoWay; tb.SetBinding(TextBlock.FontSizeProperty, myBinding); // tb is the dynamically generated control This works one way , ie from the textbox to the controls property. The problem occurs if there are 2 controls in canvas. I select first one and change fontsize to 80 using the textbox, and it shows. But when i select the second control whose fontsize is still 12,it changes to 80. I want it to be like the propertywindow of visualstudio/blend. The one way binding works without converter,anyway ill try with a converter
modified on Monday, October 19, 2009 1:42 AM
-
The controls are dynamically added to the canvas. And when a control is selected by mouse, its fontsize property is shown in the textbox. So i tried to bind the controls fontsize to the textbox // here im trying to bind the controls fontsize property to the textbox (txtFontsize) // this code runs when an control is selected unbind(); //this unbinds any control in canvas binded to the textbox myBinding = new Binding("Text"); myBinding.Source = txtFontsize; // txtFontSize is the textbox which shows the selected control property myBinding.Mode = BindingMode.TwoWay; tb.SetBinding(TextBlock.FontSizeProperty, myBinding); // tb is the dynamically generated control This works one way , ie from the textbox to the controls property. The problem occurs if there are 2 controls in canvas. I select first one and change fontsize to 80 using the textbox, and it shows. But when i select the second control whose fontsize is still 12,it changes to 80. I want it to be like the propertywindow of visualstudio/blend. The one way binding works without converter,anyway ill try with a converter
modified on Monday, October 19, 2009 1:42 AM
DeepakMega wrote:
The problem occurs if there are 2 controls in canvas. I select first one and change fontsize to 80 using the textbox, and it shows. But when i select the second control whose fontsize is still 12,it changes to 80.
When you set the binding on the newly selected control, try initializing the textbox first, something like: // here im trying to bind the controls fontsize property to the textbox (txtFontsize) // this code runs when an control is selected unbind(); //this unbinds any control in canvas binded to the textbox myBinding = new Binding("Text"); myBinding.Source = txtFontsize; // txtFontSize is the textbox which shows the selected control property myBinding.Mode = BindingMode.TwoWay;
txtFontsize.Text = tb.FontSize.ToString();
tb.SetBinding(TextBlock.FontSizeProperty, myBinding); // tb is the dynamically generated controlMark Salsbery Microsoft MVP - Visual C++ :java:
-
The controls are dynamically added to the canvas. And when a control is selected by mouse, its fontsize property is shown in the textbox. So i tried to bind the controls fontsize to the textbox // here im trying to bind the controls fontsize property to the textbox (txtFontsize) // this code runs when an control is selected unbind(); //this unbinds any control in canvas binded to the textbox myBinding = new Binding("Text"); myBinding.Source = txtFontsize; // txtFontSize is the textbox which shows the selected control property myBinding.Mode = BindingMode.TwoWay; tb.SetBinding(TextBlock.FontSizeProperty, myBinding); // tb is the dynamically generated control This works one way , ie from the textbox to the controls property. The problem occurs if there are 2 controls in canvas. I select first one and change fontsize to 80 using the textbox, and it shows. But when i select the second control whose fontsize is still 12,it changes to 80. I want it to be like the propertywindow of visualstudio/blend. The one way binding works without converter,anyway ill try with a converter
modified on Monday, October 19, 2009 1:42 AM
You might try reversing the direction of the binding. Make the FontSize the source and txtFontsize.Text the target.
-
DeepakMega wrote:
The problem occurs if there are 2 controls in canvas. I select first one and change fontsize to 80 using the textbox, and it shows. But when i select the second control whose fontsize is still 12,it changes to 80.
When you set the binding on the newly selected control, try initializing the textbox first, something like: // here im trying to bind the controls fontsize property to the textbox (txtFontsize) // this code runs when an control is selected unbind(); //this unbinds any control in canvas binded to the textbox myBinding = new Binding("Text"); myBinding.Source = txtFontsize; // txtFontSize is the textbox which shows the selected control property myBinding.Mode = BindingMode.TwoWay;
txtFontsize.Text = tb.FontSize.ToString();
tb.SetBinding(TextBlock.FontSizeProperty, myBinding); // tb is the dynamically generated controlMark Salsbery Microsoft MVP - Visual C++ :java:
This one works! Thank you.