Question

I have a UserControl which references a StaticResource which would normally be referenced in app.xaml and be fine... but my assembly is a library project so has no app.xaml. How do i reference this StaticResource now?

Here is the UserControl where I am trying to refence it

<UserControl 
   d:DataContext="{Binding Source={x:Type main:IViewModel}, 
   Converter={StaticResource viewModelLocator}}">

and here is where it would normally be in app.xaml

<Application xmlns:t="http://schemas.t.com/wpf" xmlns:app="clr-namespace:T.UI">
<Application.Resources>
    <t:ViewModelLocator 
       x:Key="viewModelLocator" 
       Container="{x:Static app:ConfigurationPlugin.Container}" />
</Application.Resources>

I just get the error message "viewModelLocator could not be resolved".

Was it helpful?

Solution

adding the resource to the UserControl's resources itself should do the trick; in fact pretty much every Wpf element has a Resources property.

<UserControl.Resources> 
  <t:ViewModelLocator x:Key="viewModelLocator"  
       Container="{x:Static app:ConfigurationPlugin.Container}" /> 
</UserControl.Resources>

OTHER TIPS

<UserControl.Resources>
   ....

unless I don't understand your question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top