« Prism 8 » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Ligne 39 : | Ligne 39 : | ||
<filebox fn='MyViewModel.cs'> | <filebox fn='MyViewModel.cs'> | ||
public DelegateCommand DoCommand { get; } | public DelegateCommand DoCommand { get; } | ||
public DelegateCommand DoWithParamCommand<string> { get; } | |||
public MyViewModel() | public MyViewModel() | ||
{ | { | ||
DoCommand = new DelegateCommand(Do, CanDo); | DoCommand = new DelegateCommand(Do, CanDo); | ||
DoWithParamCommand = new DelegateCommand<string>(DoWithParam, CanDoWithParam); | |||
} | } | ||
Ligne 49 : | Ligne 51 : | ||
private bool CanDo() => true; | private bool CanDo() => true; | ||
private void DoWithParam(string parameter) | |||
{ } | |||
private bool CanDoWithParam(string parameter) => true; | |||
</filebox> | </filebox> | ||
<filebox fn='MyView.xaml'> | <filebox fn='MyView.xaml'> | ||
<Button Command="{Binding DoCommand}" | <Button Command="{Binding DoCommand}" | ||
Content="Do" /> | |||
<Button Command="{Binding DoWithParamCommand}" | |||
CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}}" | |||
Content="Do" /> | Content="Do" /> | ||
</filebox> | </filebox> |
Version du 10 avril 2021 à 20:28
Links
Description
Fully open source version of Prism including MVVM, dependency injection, commands, EventAggregator, and others.
Prism 8 supports WPF, Xamarin Forms and UNO, but not Silverlight, Windows 8/8.1/WP8.1 or UWP.
Getting Started
- Nuget packages
- Prism.Core
- Prism.Wpf
- Prism.DryIoc
- Prism Template Pack Visual Studio extension
Dependency Injection
App.xaml.cs |
public partial class App { protected override void RegisterTypes(IContainerRegistry containerRegistry) { // register a singleton service containerRegistry.RegisterSingleton<IMyService, MyService>(); // registera transient service containerRegistry.Register<IMyService, MyService>(); } |
singleton service | for a service which is used throughout the application and that retains its state. |
transient service | create a new instance each time. |
scoped service | no implementation because unlike a web application, desktop applications are dealing with a single user and not scoped user requests. |
Commands
MyViewModel.cs |
public DelegateCommand DoCommand { get; } public DelegateCommand DoWithParamCommand<string> { get; } public MyViewModel() { DoCommand = new DelegateCommand(Do, CanDo); DoWithParamCommand = new DelegateCommand<string>(DoWithParam, CanDoWithParam); } private void Do() { } private bool CanDo() => true; private void DoWithParam(string parameter) { } private bool CanDoWithParam(string parameter) => true; |
MyView.xaml |
<Button Command="{Binding DoCommand}" Content="Do" /> <Button Command="{Binding DoWithParamCommand}" CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}}" Content="Do" /> |