WPF reuse view from different modules

3

What is the best way to reuse an vista.xaml, which belongs to another class library (another module) in WPF using MVVM?

    
asked by Jose Eduardo Poma Caceres 13.04.2016 в 18:01
source

2 answers

1

If you mean to use different Views with the same ViewModel, I do not recommend it at all. When I started with WPF I tried it and then it was a disaster to keep it. Ideally, each view has an independent ViewModel associated with it.

On the other hand, if you want to make reusable components, you can create a library of user controls (UserControl), each with its XAML and its CodeBehind, which you can use in all the projects you need.

    
answered by 12.03.2017 в 13:58
0

The simplest way is to create a project of type WPF User Control Library there you define that view as control.

Then you add the reference to the project, in order to define the namespace in the xaml, if you want to define the view, something like

xmlns:vc="clr-namespace:NombreControlLibrary;assembly=NombreControlLibrary"

You will notice that being a separate project you must define the name of assembly

How to: Import a Namespace into XAML

Note: If in the link you change the en-US by es-ES you can see the article in Spanish

    
answered by 13.04.2016 в 18:15