Coder Social home page Coder Social logo

intro.wpf's Introduction

INTRO

此项目专门用于保存我平时开发WPF使用库、文件等。

项目搭建

.net framework 优先选择4.5+ 可以使用内置的 WindowChrome

项目必要的文件夹
-Common
-Image
-Model
-Style
-Service
-View
-ViewModel

MVVM框架 mvvm light

Nuget 安装  MvvmLight

//申明ViewModel加载器
<vm:ViewModelLocator
        xmlns:vm="clr-namespace:XXX.ViewModel"
        x:Key="Locator"
        d:IsDataSource="True" />

//绑定ViewModel
DataContext="{Binding Source={StaticResource Locator}, Path=Main}"

代码段 mvvm light

mvvminpc 属性

private bool _myProperty;
/// <summary>
/// 属性.
/// </summary>
public bool MyProperty
{
    get { return _myProperty; }
    set { Set(ref _myProperty, value); }
}

mvvmrelay 命令

/// <summary>
/// 命令Command
/// </summary>
public ICommand MyCommand => new RelayCommand(() =>
{
    //代码
});

mvvmrelaycanexecute 命令(附带Canexecute)

/// <summary>
/// 命令Command
/// </summary>
public ICommand MyCommand => new RelayCommand(() =>
{
    //代码
}, () => false);

mvvmrelaygeneric 命令(带参)

/// <summary>
/// 命令Command
/// </summary>
public ICommand MyCommand => new RelayCommand<string>((e) =>
{
    //代码
});

页面跳转 Frame Navigation Service

在mvvm中如何实现UI跳转呢?
使用 NavigationService
///如果需要在cs中使用需要注册
SimpleIoc.Default.Register(() => CreateNavigationService());
///创建导航规则
private INavigationService CreateNavigationService()
{
    NavigationService navigationService = new NavigationService();
    navigationService.Configure("login", new Uri("/DMSkin;component/View/LoginView.xaml", UriKind.Relative));
    navigationService.Configure("main", new Uri("/DMSkin;component/View/MainView.xaml", UriKind.Relative));
    return navigationService;
}

///必须要在Frame中增加
<Frame x:Name="MainFrame" NavigationUIVisibility="Hidden" />

///如果想要在View层使用
DataContext="{Binding Source={StaticResource Locator}}"

///Window的CS代码或者ViewModel中使用
ServiceLocator.Current.GetInstance<INavigationService>().NavigateTo("login");
ServiceLocator.Current.GetInstance<INavigationService>().NavigateTo("main");

其他

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.