3

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

Clemens
  • 123,504
  • 12
  • 155
  • 268
Ash
  • 657
  • 9
  • 16

2 Answers2

2

Try this:

ItemsSource="{DynamicResource UsageTypeSource}}"/> 
Federico Berasategui
  • 43,562
  • 11
  • 100
  • 154
  • @Clemens not really, he's probably doing `{Binding Source={DynamicResource ..}}` which is not allowed, because the Source property of the `Binding` class is not a DP. – Federico Berasategui Mar 14 '13 at 20:42
1

Instead of

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

Use

<Control.Resources> ... </Control.Resources>