dimanche 1 février 2009

Convert "CLR method" to "ICommand" with just a XAML declaration

Introduction

When we develop an application in WPF, we want to separate

  • UI in XAML stream
  • Data (in POCO object for example)
  • Links between UI and Data, interaction logic, etc. ...

for example, The Model/ModelView/View approach try do this.

One of the technical problem of this type of architecture is "How can i launch code from UI on ModelView ?"

If I want to launch a simple public method on underneath ModelView by XAML Declaration. It is not very easy.

MethodBinding approach illustrated in this application help you to do this just with declaration syntax, no more code is necessary

Thibaud Bouquely, France, February 2009.

Demo

Demo application is Downloaded here.

in Demo tabItem, you can launch this window. It's illustrate different usage of MethodBinding XAML declaration.

=>

Tutorial

  • Create an object with a public method : the method must has no parameter or just one only

    Example :public void MyMethod(); on MyObject class
  • Push this object in DataContext of yours WPF controls

    Example :in Window's constructor : this.DataContext = new MyObject();
  • Declare link between a button and the previous public Method

    Example :<Button Command="{f:MethodBinding MyMethod}" >Clic on me
  • No more code :-)
    if you clic on the button, MyMethod() is launch on MyObject instance in DataContext of the button

Other functionality

  • If public target method has one parameter, CommandParameter on Button (or ICommandSource control) is too transfered
  • If Target object has a Read-only property named MyMethodCanExecute. It's return a boolean value, It used by MethodCommand to manage CanExecute aspect of ICommand system. (rq : target object must be a INotifyPropertyChanged or a DependencyObject/DependancyProperty to use correctly this fonctionnality)

TODO list :

  • Like BindingOperations static class of WPF, add Static method somewhere to create a MethodBinding by code
  • Improve the component ! I just try in this demos, not in real application

samedi 1 novembre 2008

New version of Datagrid with Footer

During the PDC 2008, microsoft updates WPF ToolKit with a new version of Datagrid

I just refresh my Footer's version today !

It seems work fine, the zip file is dowloaded here ...

Best Regards

Thibaud

PS : Vincent Sibal give another experimental prototype with Frozen top Row : http://blogs.msdn.com/vinsibal/archive/2008/10/31/wpf-datagrid-frozen-row-sample.aspx

Original source of Datagrid is not modified in this approach ! great !! I don't know if It is possible to do the same thing for Footer column .... not sure ....

>>

Introduction

This Datagrid control is experimental. I just try to know If I could add a Footer quickly. It seems is possible but I think a lot of bug exists in this prototype. It was a way for me to look inside the Datagrid and learn new concept and Design pattern for me. I advice to you to launch a Diff Process between original source of WPFToolKit and new version to understand all modification. Best Regards :-) Thibaud Bouquely, France, November 2008.

History :

• 2008/11/2 : new version on v1.0 of WPFToolKit (2008/10/27) without
CurrentRowIndicator
I must as some ancestor class for DataGridColumnHeader-Footer and Presenter : I am sure lot of code Header/Footer (presenter or not) should be move in these ancestors, I just do the strict necessary for the prototype.
The previous version contained CurrentRow indicator In DataGrid control, With new property Datagrid.RowHeaderTemplate, I realize this indicator with special Template in my UserControl ! It is not necessary to change Datagrid Code source to do this ! Great :-)
• 2008/09/28 : First version on beta WPFToolKit (2008/08/10) with CurrentRowIndicator

References :

Original version of Datagrid is download here :
http://www.codeplex.com/wpf/Release/ProjectReleases.aspx?ReleaseId=15598

Realease of Oct 27, 2008
First Post here : http://www.codeplex.com/wpf/Thread/View.aspx?ThreadId=36686

To use this application, click on "Load" button

Structure of Zip File

• License.txt : http://www.codeplex.com/wpf/license Associated license of WPFToolKit
• Application : This application
• Test.WpfToolKit : UserControl to Test Datagrid
• WPFToolKit : Datagrid with changes to include Footer
• WPFToolKit_2008_10_27 : Original Source of DataGrid

TODO list :

• Semantic of HeaderVisibility (include FooterVisibility : not perfect ! ;-)
• Improve the component ! I did not test Style of Footer, template, UIAutomation, etc ...
• Move some code in DatagridColumnHeaderFooterBase and PresenterBase

jeudi 16 octobre 2008

WPFToolkit DataGrid with Footer and Current row indicator

News !!

Hello
WPF is great technology and the future of the Windows IHM. But to construct a business application, some advanded controls not exists in .Net 3.50 official framework

Datagrid is one of them.

But recently, Microsoft published on Codeplex web Site a preview of interrested Datagrid (WPFToolKit) (and I hope it is the next official datagrid)

To try understand more the inside source code, I realized a small prototype to add in current version a Footer row and Current Row Indicator.

My original post in CodePlex web Site is here.

If you want to read this prototype and play with it, you can find the source zip file here.




Best regards

Thibaud