WPF, MVVM pattern, DA, etc

Hi,

i’m new in WPF and Oxygene developement.
Is there any info, demo, video how to properly develop WPF application with dataabstract using MVVM pattern ?

I found sample application that uses XSD table definitions in WPF app. But that is all.

Is in oxygene language wiki some document about WPF developement ?

How (where) to initialize datamodule class in WPF, that any modelview class can access it ?

Thanks for advance ?

Edvin

P.S: Why searching “WPF” in forum dialog returns no matches ?

Hello Edvin

At first have to mention that there is no significant difference between WPF development with Oxygene and, for example, WPF development with C#. All WPF-related approaches, advices, tutorials and (unfortunately) bugs are the same for all .NET languages. Even more - same XAML can be used in C# and Oxygene applications. All styles, behaviors and bindings syntax is completely the same for Oxygene and C# (all .xaml files are written in the XAML language regardless of the main application language).

Is there any info, demo, video how to properly develop WPF application with dataabstract using MVVM pattern ?
Unfortunately no. Could you provide a list of questions regarding this theme so I’ll provide answers you need?

However in general words WPF application that uses Data Abstract doesn’t differs conceptually from any other WPF application. In other words data access layer (regardless is it based on Data Abstract, WCF or any other technology) should be separated from ViewModels layer, which, in turn, should be separated from the Views layer.

How (where) to initialize datamodule class in WPF, that any modelview class can access it ?
This is a question of the software architecture area, so there is no answer that will be correct in all situations. For example for simple quick’n’dirty prototype app DataModule can be instantiated directly in the code-behind of the main WPF application form. In more advanced architecture DataModule could be hidden behind an interface that is later injected into instantiated ViewModels using some IoC container.

So WPF application development approaches ae the same for Oxygene and, for example, C#. Also when the Data Access Layer is clearly separated from the other application code layers it is not important (from the application architecture point of view) which exactly technology is actually used to access the data.

Hi Anton.

Thanks for your response.
I know that my questions was very basic.

But still hope some demo exists.

I will prepare some questions and post in here.
Thanks again.

Edvin

Hello again Edvin

Please take a look at http://blogs.remobjects.com/blogs/mh/2012/10/09/p4850
The WPF wizard application shown in this blogpost was created using Oxygene. It uses MVVM and IoC approaches (namely it uses MVVM Light as MVVM helper library and autofac as Dependency Injection container)

Hi Anton.

Thanks for your hint.
Is there any code of that wizard ?

Anton do you mean MVVM Light at: http://www.galasoft.ch/mvvm/ ?

And, fwiw, MVVM is just a pattern and does not require a 3rd party framework such as MVVM Light, etc.

Yes of couse. But some of them could be very handfull.

And, fwiw, MVVM is just a pattern and does not require a 3rd party framework such as MVVM Light, etc.
Indeed 3rd partly frameworks aren't required to create MVVM applications, but they provide tools and routines intended to make developer's life easier.

By mentioning MVVM Light I didn’t intended to recommend (or to not recommend) any particular library of framework. My intention was to show that creating WPF applications in Oxygene doesn’t differ (approach- and methodology-wise) from creating WPF applications in any other .NET language.

Anton.

Thank you for your opinion.

But still. Can you suggest some third party MVVM framework ?

I find the additional frameworks just introducing constructs that are harder to understand (though more general). If you are just starting with MVVM, I would do it without a framework first so that you have a really good understanding of MVVM. THEN maybe move to the frameworks. I suspect MVVMLight, as was mentioned, is the most popular.

Prism is also quite powerful and popular MVVM framework. It well documented and contains a lot of samples to get started with it. Though some of developers can consider it as heavy and suitable for large projects.

Hi Mtiede, AlexK.

Thanks both for your suggestions.
Like Mtiede said in my first step i will try with pure MVVM.

Because i’m new in WPF and .NET developement (+15 years on Delphi), everything is new for me.

If you are developers in WPF, can you help me how to share code between viewmodels.

I mean - how to share datamodul class with shared data ?
Where and when should i instantiate that shared clasess ?

For now i’m able to bind view with viewmodel (data and commands).
In next step i wish to connect to RODA server (in data modul class).

Thanks for any hint.

Edvin

I’ve been doing Pascal since Turbo Pascal 1.0. So I’ve spent a lot of time in Pascal and Delphi, also. I haven’t used Delphi for a couple of years now (I have a terrible sense of time, so it might have been longer or shorter). I can’t imagine going back to Delphi. Too restrictive. Xaml is a lot more powerful than the Delphi DFM, etc.

I don’t think there is anything directly analogous to Datamodule. If you want to share code, the best thing is to make a class library and then just “add reference” to it in your projects.

I would put the Viewmodel class in a class library. In fact, I normally create a Viewmodels assembly and a Views assembly so that are completely independent of each other. Then the main app joins the two together using a Page that instantiates the View and the Viewmodel and makes the Page DataContext be the Viewmodel instance.

Hi mtiede.

Thanks for your response.
Can you be more precise ?

I knows how to use reference to other assemblies.
But i don’t know where instantiate shared classes and how to pass reference of that clasess to modelview classes.
Is app class apropriate place ?

Thanks again for your time.
Edvin

I almost exclusively do Silverlight, but I think WPF does the same sorts of things. You can either have an instance of a shared class created by the App or you could create a Resource. Here is what I do for a Page:

<UserControl

x:Class=“MvvmBase16.Pages.MainPage”

xmlns=“http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=“http://schemas.microsoft.com/winfx/2006/xaml
xmlns:d=“http://schemas.microsoft.com/expression/blend/2008
xmlns:mc=“http://schemas.openxmlformats.org/markup-compatibility/2006

xmlns:viewmodels=“clr-namespace:MvvmBase16.Viewmodels”
xmlns:views=“clr-namespace:MvvmBase16.Views”

mc:Ignorable=“d”
xmlns:navigation=“clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation”

<UserControl.DataContext>
viewmodels:MainViewmodel/
</UserControl.DataContext>

views:MainView/

And here is the View:

<UserControl

x:Class=“MvvmBase16.Views.MainView”

xmlns=“http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=“http://schemas.microsoft.com/winfx/2006/xaml
Width=“400”
Height=“300”

  <Grid.RowDefinitions>
     <RowDefinition Height="Auto"/>
     <RowDefinition Height="Auto"/>
  </Grid.RowDefinitions>

  <TextBlock 
     Text="Main View"
     />
  <ComboBox DataContext="{Binding CategoriesViewmodel}" ItemsSource="{Binding Categories}" DisplayMemberPath="Name" Grid.Row="1"/>

And here is the Viewmodel:

namespace MvvmBase16.Viewmodels;

interface

uses
MyLibrary,
System.Collections.Generic,
System.Text,
System.Windows,
MvvmBase16.Commands,
MvvmBase16.Managers;

type
CategoriesViewmodel = public class
public
constructor;
property Categories : Categories; notify;
end;

  MainViewmodel = public class
     public
        constructor;
        property CategoriesViewmodel : CategoriesViewmodel;
     end;

implementation

constructor MainViewmodel;
begin
CategoriesViewmodel := new CategoriesViewmodel;
end;

constructor CategoriesViewmodel;
begin
Categories := new Categories;
end;

end.

If I wanted one instance per app, I would create it in the App Startup event handler.

Hope this helps.

(don’t know how to mark up this post so that it doesn’t get rid of my indentation. crap, and it stripped out my markup too. Can’t find anywhere here that says what to do.)