WPF/MVVM windowsservice without viewmodel reset

后端 未结 2 1416
既然无缘
既然无缘 2021-01-17 03:11

I\'m want to remove from my view model\'s creating of view\'s

I wrote WinodwsService class to creating a new window:

public class WindowService : IWi         


        
相关标签:
2条回答
  • 2021-01-17 03:42

    instead of initializing DataContext in xaml

    <UserControl.DataContext>
        <local:PolaPrzewoznikowViewModel />
    </UserControl.DataContext>
    

    I suggest to use DesignInstance:

    <UserControl d:DataContext="{d:DesignInstance Type=local:PolaPrzewoznikowViewModel, 
                                 IsDesignTimeCreatable=True}" ...>
    

    It will give IntelliSense and designer enough information in design-time, but a new instance won't be created in run-time (there will only DataContext from WindowService)

    0 讨论(0)
  • 2021-01-17 03:42

    Why are you setting both the content and the datacontext of the window?

    Regarding intellisense you should do as ASh suggests, the data context by its nature will be available to all view descendants.

    If you don't want to implement the window service yourself you can always use my framework https://github.com/FantasticFiasco/mvvm-dialogs.

    0 讨论(0)
提交回复
热议问题