If you want to set the focus to the selected item in your Silverlight Listbox Control you have to use this dirty trick:
Freitag, 30. Juli 2010
If you are using a MVVM pattern with a view model you have generally the problem to bind a combobox inside a Datagrid because you cannot access the data context of your view by referencing with the elementname syntax. The trick to bind your Comboxbox inside a DataGridTemplateColumn is to define the reference to your viewmodel with a StaticResoucre and use this for the DataContext-Binding and combobox-Binding:
StaticResoucre of the viewmodel
Binding the view to your viewmodel
Combobox-Binding in the Datagrid
Samstag, 17. Juli 2010
If you use the new Silverlight 4 controls for drag&drop you have sometimes the problem that in your control the drag Event started even if you only select the next item in your listbox or treeview. The reason for this is that you maybe have long running events at your SelectedItem-Events. This forces the Drag&Drop-Container to raise a DragEnter-Event because the control does not become the MouseUp-Event in the desired time.
To solve this problem we made in our current project several approaches (Background process etc.). But the best way to reach your goal is a very “oldschool” method:
Using a timer to make your long running events in the SelectedItem-Event
On SelectedItem Changed:
If you use a dataform with the autogenerate property set to true, you can customize the behaviour and the look and feel of the dataform in the OnAutoGeneratingField Event.
For example you can set the look and feel of required fields to your individual style.
1. step: DataAnnotation for your properties
2. step: Override OnAutoGeneratingField
Define your own DataForm control which inherits from DataForm. Then you can override the OnAutoGeneratingField method and do a lot of tricky things. Manipulating the behaviour of your autogenerated datafields or give them a different style. In my example we used in our project this mechanism to attach a GotFocus and LostFocus-Event to each TextBox and DatePicker, if there is a Required-Attribute defined.
The GotFocus- and LostFocus-Events looks like this:
In this Eventhandlers we use the VisualStateManager to give the controls, if the content is empty, a new visual state “Required” or in the other case the visual state “NotRequired”.
Now you have only to define the two new states in your style and you can enjoy the new Required field effect.
3. step: Add new States to your style
In the VisualStateManager section:
The content style:
Samstag, 10. Juli 2010
You can use RIA services as a normal WCF service with several clients. For example as Excel OData-Source or as data delivery service for your Windows Phone 7 application. To achieve this goal you have to install the latest RIA Services Toolkit and do a little configuration work.
Reference for Microsoft.ServiceModel.DomainServices.Hosting
Add a reference of Microsoft.ServiceModel.DomainServices.Hosting to your RIA Services project.
It is important that you choose the version which was shipped by the RIA Services (Silverlight) toolkit. The standard standard assembly from the SDK does not contain the SoapXmlEndpointFactory and JSonEndpointFactory.
So take this one:
For the OData endpoint you need the System.ServiceModel.DomainServices.Hosting.OData assembly from the SDK directory.
Configure the endpoints
Configure the Json, Soap and OData endpoints in the web.config:
Using of RIA Services in your Windows Phone 7 application
To use the rias service (Soap endpoint) in your Windows Phone 7 application you have only to add a new reference and enter the Uri of your ria service.
Your Uri consists of the <namespace of your ria service>-<classname of your ria service>.svc where “.” are replaced with “-“ !
Now you can create a proxy client and access to your Domainservice methods:
Uri of all endpoints
The Uri for our exposed endpoints are:
SOAP: http://localhost:[portnumber]/<namespace of your ria service>-<classname of your ria service>.svc
With these exposed endpoints, you can talk to multiple clients:
- Excel Power pivot - Using the OData endpoint
- Windows Phone 7 – Using the SOAP endpoint
- AJAX client – Using the JSON endpoint
Samstag, 3. Juli 2010
Sometimes it is necessary that you have a converter (interface IValueConverter) with multiple parameters. To reach this goal, you can use a DependencyProperty. That’s normally a very easy step, but I spend some extraordinary time with my converter becuase in my case the second parameter should be bindable
– So what was the problem?
I have tried to derive the Converter from UserControl – great mistake: You have to use FrameworkElement instead!