question

ArathiJinde-8885 avatar image
0 Votes"
ArathiJinde-8885 asked HuiLiu-MSFT edited

In WPF which is better MVVM way of loading an userControl/customcontrol from a different library project into mainWindow XAML

there is seperate library for usercontrol which has to be loaded in another exe console project which is better approach for the same 1. using contentcontrol and set the content to the user control 2. refer the library in the mainwindow.xaxml and add the usercontrol inside the xaml <lib:userControl> or any other better way of achieving this ?

dotnet-wpf-xaml
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@ArathiJinde-8885.
Your description makes me feel a little confused. Do you want to load user control into another exe console project? What is your user control like, can you give me any code snippets to analyze? Does your Mainwindow have anything to do with your console app? MVVM pattern helps to cleanly separate the business and presentation logic of an application from its user interface (UI), it seems not to add the lib into another project. By the way, an answer from PeterFleischer-3316 gives a good MVVM sample of using contentcontrol and set the content to the user control, you can refer to it.


0 Votes 0 ·

1 Answer

essamce avatar image
0 Votes"
essamce answered

hi @ArathiJinde-8885
i think user control is meant to be project specific unlike custom control which meant to be a general purpose, however regarding your question since you didn't show your code we assumed the UserControl has it's viewmodel
you likely will use it like so <lib:UserControlView DataContext="{Binding UserControlViewModel }">

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.