anyone got any good WPF learning resources?

Soldato
Joined
16 Jun 2013
Posts
5,375
I'm sitting here looking at one fugly windows form application and reading up it appears WPF is the way forward. So trying to rewrite my code to adopt a WPF UI.

I cant even get my head around adding listview items from an array in WPF :(.

Anyone got any recommended reading?
 
Associate
Joined
14 Mar 2007
Posts
1,667
Location
Winchester
wpf is dead too :) allegedly.

I wouldn't bother specifically learning WPF, learn universal apps if you are on Win10 development is essentially the same (xaml and generally mvvm) and whetver language you prefer c# or vb.netbut it will/may work for any device.

One thing to get out of your head is that you can still virtually do everything you want in WPF using the same techniques as WinForm, i.e.
me.ComboBox.value = "some value", but you shouldn't, but sometimes to be fair the WPF is so complicated its just easier to do it that way.

In WPF you use binding in XAML to do the equivelant and bind to a property in some class somewhere, i.e. in the viewmodel.

In the constructer of the code behing you can do:

me.datacontext or this.datacontext(c#) = myclass

<TextBox Value = {Binding MyProperty}/>

Advantage of this is that WPF (if you implement the right interface or simply use the code behind module) implements on property changed. So if the value of your property changes the value of the control changes too.

If you get your head around that you are half way there.

Best source is MS Virtual Academy imo
 
Last edited:
Soldato
OP
Joined
16 Jun 2013
Posts
5,375
Thanks for that.

I think that's the part I'm struggling with. Trying to work my classes into a WPF format where I should really be rewriting them completely.

Ill take a look at universal.

Considering how long its been around its not very nice to work with. Guess I'm just not used to it being my first C# attempt.

About time I added some of it to my skillset though.
 
Associate
Joined
14 Mar 2007
Posts
1,667
Location
Winchester
What I do and I try to keep my stuff simple as I'm far from an expert is something like this from the top of my head. I'm vb.net but the idea is the same in c#

So I will have a class for all my basic date models:

Person Class

Public Property Forename as string
Public Property Age as integer
Public Property Forename as string

Public SUb New(paramters....)
create the properties in your dal or whether and pass values to constucter
End Sub

other methods.....properties
End Class

Then a class for each view, i.e what you define as a view is different for everybody, some people will go as far as having a class for each control or collection of controls, I think that is way too complex.

i'm lazy so this would be a singleton, but other people would recommend some design paradigm, di or something
ViewModel Class
Implements On Property Changed


Public Property PersonCollection as New ObservableCollection(Of Person)
other methods.....properties

You should also handle any UI events in here, i.e. clicks

End Class

Now in code behind in the constructer or in universal the overridden on navigated to method, something like this.

Public Sub New

Call the dal class or method and pass to it either the class or collection I am interested in:

Dim vm as new viewmodel
Dim dal as new dalclass

If dal.getdata(vm) = false then do whatever I need to do

....if not

me.datacontext = vm

End Sub

Once you have got that far your person collection will be available to bind in your xaml so you could go something like:

<Listview ItemSOurce="{Binding PersonCollection}"/>

You will also need a datatemplate for your person class defined in xaml so the front end knows how to visualize your items in the listview.

I've been doing it 5 years and I feel like I know only about 10% of what can actually be done.
 
Soldato
OP
Joined
16 Jun 2013
Posts
5,375
Think I get it :).

Time to have a shot.

Thank you!

I've only been using C# for the past 7 days so I'm currently at hack and slash stage. Shame I cant make winform look good :D.
 
Associate
Joined
16 Aug 2010
Posts
1,373
Location
UK
C# is a wonderful language and using it with visual studio is great (along with the resharper plugin). It's worth the effort in learning :).
 
Soldato
OP
Joined
16 Jun 2013
Posts
5,375
I've used other C languages before so the transistor isn't too bad. So far it seems to make sense :). I'll have a look at that plugin thanks :).

Cheers for the link joelk.

Edit: never mind I had a check the wrong way round.
 
Last edited:
Associate
Joined
7 Nov 2013
Posts
255
Location
Kent, England
If you are new to WPF and MVVM you may find it easier to use an existing framework such as MVVM Light or Prism (I prefer Prism). This will mean you have plenty of samples and examples and other people will be knowledgeable about the approaches you are taking. As you build and extend your application you will learn how these frameworks function under the cover and pick it all up at a much easier pace :)
 
Back
Top Bottom