- 導入CommunityToolKit? vs2017只能導入7? ? ?
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input;namespace WpfApp1.viewmodels {public partial class TestMvvm:ObservableObject{private string _name = "old";public string Name{get => _name;set => SetProperty(ref _name, value);}public IRelayCommand ChangeText { get; }public TestMvvm() { ChangeText = new RelayCommand(()=> { Name = "new"; }); }} }
屬性得自己寫 用不了[ObversableProperty]? ? RelayCommand得自己實現
改StartUpUri
StartupUri="views/MainWindow.xaml">
用斜線不用點
加DataContext
<Window.DataContext><local:TestMvvm></local:TestMvvm></Window.DataContext>
? ??
改x:class
x:Class="WpfApp1.views.MainWindow"
? ?總結? ? 有mainwindow的地方都要改? 路徑多加一個views
在 C# 中,命名空間通常是?
項目名.文件夾名
(如果文件夾有嵌套命名空間)。就不用viewmodels.WpfApp1.viewmodels? 直接項目名.文件夾名即可??
? ? ? ? ? ? ??????????????????????????????????????????????也就是命名空間不需要加文件夾名