how to refer both view model and global syles.xaml page in the User Control page in WPF

StackOverflow https://stackoverflow.com/questions/23669828

  •  23-07-2023
  •  | 
  •  

Pergunta

I am new to WPF and I am using a MVVM pattern. I have a view model that has to be refer in the view and at the same time I have a global styles that has to be refer. I am adding the references in resources of the User Control Page, but it is not allowing two references. only one refrence can be added. below is my code.

<UserControl.Resources>
    <vm:UpdateControlViewModel  x:Key="UpdateControlViewModel">    
    </vm:UpdateControlViewModel>
//here i want to add style refrence.
</UserControl.Resources>  

any help would be appreciated.

Foi útil?

Solução

you have to use a resource dictionary. something as below.

<UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/Styles.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
    <vm:UpdateControlViewModel  x:Key="UpdateControlViewModel"></vm:UpdateControlViewModel>
        </ResourceDictionary>
</UserControl.Resources>

considering your styles.xaml page is in resources folder of your project. hope this helps.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top