Wpf Dynamic UI - Hello world quickstart guide.

Requirements:

  • Visual Studio 2010.
  • Nuget package manager

 

  1. Create a Wpf application.

    image
  2. Add nuget package reference. Search for WpfDynamicUI

    image
  3. Create the hello world model

    public class HelloWorldModel : INotifyPropertyChanged
    {
    private string _message;
    private string _username;

    public string Username
    {
    get { return _username; }
    set
    {
    if (_username != value)
    {
    _username = value;
    OnPropertyChanged("UserName");
    OnPropertyChanged("CanSayHello");
    }
    }
    }

    [Editable(false)]
    public string Message
    {
    get { return _message; }
    private set
    {
    if (_message != value)
    {
    _message = value;
    OnPropertyChanged("Message");
    }
    }
    }

    [Display(AutoGenerateField = false)]
    public bool CanSayHello
    {
    get { return !string.IsNullOrEmpty(_username); }
    }

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    #endregion

    protected virtual void OnPropertyChanged(string propertyName)
    {
    if (PropertyChanged != null)
    PropertyChanged(this,
    new PropertyChangedEventArgs(propertyName));
    }

    public void SayHello()
    {
    string message = string.Format("Hello '{0}'", Username);
    Message = message;
    }
    }
  4. Add DynamicModelControl and DataContext to Window Xaml 

    <Window x:Class="WpfDynamicUISampleApplication.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WpfDynamicUISampleApplication="clr-namespace:WpfDynamicUISampleApplication"
    xmlns:WpfDynamicControl="clr-namespace:Csizmazia.WpfDynamicUI.WpfDynamicControl;assembly=Csizmazia.WpfDynamicControl"
    Title="MainWindow" Height="350" Width="525">
    <Window.DataContext>
    <WpfDynamicUISampleApplication:HelloWorldModel/>
    </Window.DataContext>
    <Grid>
    <WpfDynamicControl:DynamicModelControl x:Name="dynamicDisplay" DisplayMenu="False"/>
    </Grid>
    </Window>
  5. Run the application (first try)

    image
  6. Add Theme resource dictionary to application resources

    <Application x:Class="WpfDynamicUISampleApplication.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="MainWindow.xaml">
    <Application.Resources>
    <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/Csizmazia.WpfDynamicControl;component/Themes/Generic.xaml" />
    </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    </Application.Resources>
    </Application>
  7. Run the application again (now with some more visuals)

     image

 

Enjoy your first Wpf Dynamic UI application.

 

Wpf Dynamic Hello World source – download

Last edited Apr 15, 2012 at 4:54 PM by csizo, version 10

Comments

No comments yet.