Showing posts with label XAML. Show all posts
Showing posts with label XAML. Show all posts

Windows Store MVVM Template

A bare bones starter template for Windows Store 8.1 Projects that Utilizes the Model View View Model Pattern

You can download the template from the Visual Studio Extension Gallery
You can fork or contribute to the template on github.com/KyleMit/WindowsStoreMvvmTemplate

Directory:

Here’s a breakdown of the directory structure:

directory

  • Assets: contains images for the Package.appxmanifest
  • Model: contains core business logic for the application
  • Resources: contains common resources for the whole application
    • AppResources.xaml: contains xaml resources that is added to App.Resources
  • Utilities: contains reusable helper classes that can be used in this, and other, projects.
    • BindableBase.vb: implements INotifyPropertyChanged which can be inherited by classes in you ViewModel
    • NavigationHelper.vb: adds Navigation support and Process Lifetime Management
    • RelayCommand.vb: implements ICommand to help invoke delegates through binding.
    • SuspensionManager.vb: captures global session state to simplify process lifetime management
  • View: contains views for the User Interface layer of the application
    • MainView.xaml: has the initial window that the application launches
  • ViewModel: contains classes which help communicate between the View and the Model
    • MainViewModel.vb: contains the business logic for MainView.xaml
  • App.xaml: contains resources scoped to the entire application
    • App.xaml.vb: contains startup code for the application

Samples:

Binding

MainView.xaml

<TextBox Text="{Binding PersonName}" />

MainViewModel.vb

Private _personName As String
Public Property PersonName As String
    Get
        Return _personName
    End Get
    Set(ByVal value As String)
        SetProperty(_personName, value)
    End Set
End Property

MainViewModel.cs

private string _propertyName;
public string PropertyName {
    get { return _propertyName; }
    set { SetProperty(ref _propertyName, value); }
}

Commands

MainView.xaml

<button content="Say Hello" command="{Binding SayHelloCommand}" />

MainViewModel.vb

Public ReadOnly Property EnterNameCommand As RelayCommand
    Get
        If _enterNameCommand Is Nothing Then
            _enterNameCommand = New RelayCommand(Async Sub() Await EnterName())
        End If
        Return _enterNameCommand
    End Get
End Property

Private Function EnterName() As Task
    'do awaitable stuff here
End Function

Windows 8 App Development Presentation

Here’s a list of all the resources I’ve put together for my talk on Windows 8 Application Development that I gave at:

You can view the slides from my presentation or rate the talk if you’d like to provide some feedback

The BindableBase class helps implement the MVVM pattern by implementing INotifyPropertyChanged on a base class which should be inherited by classes in your ViewModel

The RelayCommand class helps implement the MVVM pattern by exposing methods on your ViewModel as Properties to which your View can Bind

The UserSettingsBase class provides base functionality that allows you to create persistent user settings with regular Property Syntax.

The SettingsHelper class takes care of the plumbing to link the Settings Charm Panel with your own User Controls.

NOTE: As of Windows 8.1, winRT released a native SettingsFlyout so the following code is primarily for historical purposes.

You can download the MVVM template in the Visual Studio Extensions Gallery
Fork or contribute to it on GitHub
Or read about it in my Blogpost.

For the Full Word Guesser Application in the Windows Store :

Here’s a SkyDrive Folder with all the files you might need. In here, you’ll find the PowerPoint, Demo Source Code, Resharper Templates, and code from the Demo.