Silverlight DataForm - Nested Dataform - How to BeginEdit? - silverlight

I have a Silverlight User Control. This contains a DataForm. This DataForm nests another Silverlight User Control, which also contains a DataForm.
I have bound the nested dataform successfully to an object in the parent control.
I can NOT however, get the nested control to enter Edit mode along with the parent. I have tried calling it directly by using the FindNameInContent method to return the nested dataform and then called BeginEdit() but this fails (returns false).
Stuck.

I had a simpler scenario but a similar problem. In my scenario I had a DataGrid directly nested inside a DataForm, and was unable to synchronize the edit modes of the two controls until I realised that I needed to implement an EditTemplate for the DataForm, as well as the ReadOnlyTemplate, and implement the DataGrid in both. I set IsReadOnly=true for the DataGrid in the ReadOnlyTemplate and IsReadOnly=false for the DataGrid in the EditTemplate, and it all works smoothly, with no code.
Dave.

Related

Silverlight TextBox cant get focus

I have several controls in my silverlight view including telerik and my own controls(Custom controls).in this view there is a TextBox called AppointmentSubject which needs to be focused when i open this view.this textbox is also a custom control.I did following thing inside the View_Loaded method.
System.Windows.Browser.HtmlPage.Plugin.Focus();
//TextBoxName.Focus()
AppointmentSubject.Focus();
But AppointmentSubject only gets focused when i open the view second time.Any idea how i achieve it right first time?

MVVM and updating WPF DataGrid Layout

I am using MVVM via Caliburn Micro. I have a datagrid bound to a list of view models. I am running a process in a background thread that updates the datagrid's item viewmodels one at a time.
Everything is working great, the data grid's items update in real time as each of the item viewmodels get updated, just as you would expect.
One small problem: When an item's view model update occurs, the datagrid's layout get mucked up. For example, if I update an item's status from "OK" to "Oh no, something bad happened", that column get re-sized appropriately, but the subsequent columns get shrunk, obscuring the content in them.
If I refresh the entire grid, then everything get laid out appropriately.
Since I am using MVVM, I don't have access to the datagrid control itself, so I cannot use the datagrid's UpdateLayout method directly.
I could use CM's ViewAware view model, but that seems like it should be unnecessary.
Any ideas?

WPF patterns: Items and ItemsSource

Well I'm designing a Custom WPF control - fore the sake of learning - that display logs message in a similar way Visual Studio does. I want to allow the user add messages by adding message istances to an Items collection, or by binding to an ItemSource. I think this is a well established pattern in many wpf controls, but I have no Idea on how achieve it. I know I can obtain the same result by adding a listview as a part of my control, but the project goal is learning, so I prefer avoid that solution. Any idea ?
Have a read around the ItemsControl, your custom control can inherit from an ItemsControl, or a derivative of it. If you create an ObservableCollection containing your items and bind that to your ItemsSource, then your list will be automatically updated. You can style the ItemTemplate and Template to give the list a different look and feel.
There's loads of info here

Enable or Disable multiple controls in Silverlight

What is considered the best way of enabling or disabling multiple controls in Silverlight at the same time (textbox, combobox, autocompletebox and the like)?
I suppose I could bind the "IsEnabled" property of each control to a boolean property. That property only exists for interactive controls and not textblocks.
I could loop through the children recursively and set their properties appropriately, but that seems inelegant.
Ideally, I'd like to just set some disable-like property on the parent container of the controls, giving even the TextBlocks a disabled look similar to a Windows form.
Is there a way to just disable the parent container?
Use the ContentControl Silverlight provides.
<ContentControl x:Name="GroupOfControls" >...Your controls...</ContentControl>
//Enable and Disable
GroupOfControls.IsEnabled = false;
You could use a ViewModel approach similar to the answer in StackOverflow 1545844
By having a calculated IsEnabled property you can then bind the elements in the View which should be controled by this property.
Usually I always create a ControlHandler Class that does all the updates on my controls. (Just to separate concerns)
Recently we had to reset all controls on the form and didn't want to loop through every single control.
All control-related data logic gets updated in the ControlHandler class.
We then only apply the values appropriate values / properties onto our controls.
This is a workaround but worked pretty well and also cleanly for us.
There are, of course, better ways to solve that..
I was looking into disabling multiple controls when fetching data from a web service.
The BusyIndicator control got me what I needed with very little effort.
Maybe it'll be a good enough solution for others as well.
Wrap with UserControl and set its IsEnabled property.
...

Silverlight databinding a textBlock in another user control

I have a small usercontrol that basically increments or decrements a value by one. The user control has two buttons(one to add and the other to subtract) and a textBlock that is used to display the value.
I am going to have multiple instance of this usercontrol in another usercontrol so I can manipulate values of a dataclass that has an INotifyPropertyChanged interface. My question is how can I databind the textBlock of the value changing usercontrol to the usercontrol I instansiated it in?
First, I want to state that Silverlight 2 does not support element to element binding. That feature is added in Silverlight 3 (out in Beta now). Having said that, I don't think you want to bind controls together anyway. It sounds like you're trying to build a NumericUpDown control and you probably have some class in code behind that's actually doing the incrementing and decrementing.
If that's the case, you can simply subscribe to the click handlers and call a method on your model like Increment or Decrement. Your model can expose a property for the current value and that property is what is bound to your text box.
Now if you're actually trying to build a NumericUpDown control, you might want to check out the Silverlight Toolkit. The toolkit already includes this control and it also supports data binding.
Check out the NumericUpDown Control here and download the toolkit here.
Finally, binding from a child control to a parent control really isn't any different. The parent UserControl has a DataContext and all child controls inherit that. Each individual child control can also have its DataContext set. Binding expressions are always relative to the DataContext and the DataContext can be set in code. In your case, probably to a model of some sort.
I hope that helps.

Resources