Question

I have a child usercontrol and I am having trouble accessing its parent usercontrol's resources. The resource is a collectionViewSource and its source is set in the code behind of the parent usercontrol, the source is set to a query result from LINQ to SQL. Both usercontrols are defined in their own xaml file. I tried using DynamicResource and it complained saying it needs to be used with a DepenednecyProperty or so...

parent usercontrol:

...
<UserControl.Resources>
    <CollectionViewSource x:Key="UsageTypeSource"/>
</UserControl.Resources>
...

child usercontrol:

...
<ComboBox Height="28" HorizontalAlignment="Left" Margin="147,1,0,0" x:Name="cbxUsage"
          Grid.Column="1" Grid.Row="2" Width="186"
          SelectedItem="{Binding Path=UsageType, ValidatesOnExceptions=true, NotifyOnValidationError=true}"
          VerticalAlignment="Top" SelectedValuePath="ID"
          SelectedValue="{Binding Path=Usage}"
          ItemsSource="{Binding Source={StaticResource UsageTypeSource}}"
          DisplayMemberPath="Type"/>
...

The error I am getting is 'The resource "UsageTypeSource" could not be resolved'

Can you provide the proper way to access the resource

Thanks in advance Ash

Was it helpful?

Solution

Try this:

ItemsSource="{DynamicResource UsageTypeSource}}"/> 

OTHER TIPS

Instead of

<UserControl.Resources> ... </UserControl.Resources>

Use

<Control.Resources> ... </Control.Resources>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top