新建wpf項目,nuget引入Prism.DryIoc,MaterialDesignThemes
引入后,修改App.xaml 前臺引入 xmlns:prism="http://prismlibrary.com/"和prism:PrismApplication App.xaml.cs
App.xaml.cs繼承PrismApplication,重寫CreateShell和RegisterTypes
protected override Window CreateShell(){return Container.Resolve<MainWindow>();}protected override void RegisterTypes(IContainerRegistry containerRegistry){}
MainWindowViewModel繼承BindableBase,實現mvvm
上面步驟,同樣可以通過新建prism 項目,自動引入引入了prism
在model中新建屬性,實現屬性自動通知功能
private double _total;public double Total{get { return _total; }set{_total = value;RaisePropertyChanged();}}
前臺綁定
<TextBox VerticalAlignment="Center" x:Name="Total" Text="{Binding Total}" Width="70" Margin="4 0 0 0" TextAlignment="Center" BorderThickness="0 0 0 2"></TextBox>
? 新建Command
?? ??? ? ?public DelegateCommand SelCommand { ?get; set; }
?? ??? ? ?
在構造函數中,綁定委托方法
?? ??? ? ?SelCommand = new DelegateCommand(()=> {
?? ??? ? ? ? ?SelectDish();
?? ??? ? ? ? ?DispAllSelect();
?? ??? ? ?});
?如果方法帶有參數,可以使用DelegateCommand<T>泛型聲明
前臺綁定控件Command屬性調用
?? ??? ? ? <CheckBox ?IsChecked="{Binding IsSelected,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Command="{Binding DataContext.SelCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" ></CheckBox>
最后實現簡單的Order系統
代碼地址: