Creating an MVVM friendly dialog strategy

后端 未结 3 679
名媛妹妹
名媛妹妹 2020-11-28 06:32

I\'m trying to create a strategy for handling popup forms for use throughout any part of my application. My understanding so far is that I will need a single UserContr

3条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 06:42

    I recently started learning MVVM for a WPF app I was creating, I used this article as a basis for showing dialogs, if you download the sample project then it is actually quite a nice decoupled method, it is nicely abstracted and to get a view you pass an instance of a viewmodel. I extended it somewhat for my own means, I also used the WPFExtendedToolkit MessageBox for warnings, errors etc because the standard win32 MessageBox is fugly.

    With regards to dynamic forms then you'll want to investigate the ItemsControl, and in your ViewModels have a Collection of Data Items which need to be edited by the user for the ItemsControl to bind to. I have a dialog for editing actions and their parameters in a workflow system designer where the dialog list of actions was totally dynamic. This was done by exposing a collection of my items with their data types so I could then use a DataTemplateSelector to select DataTemplates which contained the correct types of controls, i.e. a datatype of DateTime showed a DatePicker.

    Hope That Helps

提交回复
热议问题