Reputation: 1530
I have a usercontrol1.xaml where I have a resource defined:
<UserControl x:Class="FrameworkDemo.usercontrol1View">
<UserControl.Resources>
<local:DemoManger x:Key="demoManager"/>
<local:DemoManagerConverterx x:Key="demoManagerConverter" Manager="{StaticResource strategyManager}"/>
</UserControl.Resources>
<telerik:RadTileView MinimizedItemsPosition="Top">
<telerik:RadTileViewItem>
<local:UserControl2View/>
</telerik:RadTileViewItem>
<telerik:RadTileViewItem>
........
</telerik:RadTileViewItem>
</telerik:RadTileView>
</UserControl>
Then in the user control view 2, I want to have this situation:
ss
<UserControl x:Class="FrameworkDemo.usercontrol2View">
<DockPanel>
<ComboBox MinWidth="270" Margin="0,0,5,5"
ItemsSource="{Binding Path=Demos, RelativeSource={RelativeSource AncestorType={x:Type local:DemoManager}}}"
SelectedValue="{Binding Path=CurrentStrategy, Converter={ ????}, Mode=TwoWay}"
IsEnabled="{Binding CanRefreshExecutionList, ElementName=Instance}"
DropDownOpened="StrategyComboBox_DropDownOpened">
</DockPanel>
</UserControl>
I was able to link to the parent control for the ItemSource, but for the converter how can I do it?. I can not event move the resource definition from control1 to control2. Inside of the RadTileViewItem is not possible to add another resource. Exactly in usercontrol1View I have a tabcontrol inside the RadTileViewItem and inside the tabiteam i have inlcluded the UserControl2View.
How can I link to the parent resource for the covnerter?
Upvotes: 0
Views: 715
Reputation: 169420
How can I link to the parent resource for the covnerter?
You can't. If you need to use the same converter in both UserControls
, you have defined the resource in the wrong place actually.
You could either move it to your App.xaml
file:
<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
StartupUri="MainWindow.xaml">
<Application.Resources>
...
<local:DemoManagerConverterx x:Key="demoManagerConverter" Manager="{StaticResource strategyManager}"/>
</Application.Resources>
</Application>
Then you will be able to reference it across your entire application. The other option would be to define another resource of the same type in UserControl2
:
<DockPanel>
<DockPanel.Resources>
<local:DemoManagerConverterx x:Key="demoManagerConverter" Manager="{StaticResource strategyManager}"/>
</DockPanel.Resources>
<ComboBox MinWidth="270" Margin="0,0,5,5"
ItemsSource="{Binding Path=Demos, RelativeSource={RelativeSource AncestorType={x:Type local:DemoManager}}}"
SelectedValue="{Binding Path=CurrentStrategy, Converter={StaticResource demoManagerConverter}, Mode=TwoWay}"
IsEnabled="{Binding CanRefreshExecutionList, ElementName=Instance}"
DropDownOpened="StrategyComboBox_DropDownOpened" />
</DockPanel>
But you can't reference a resource that is defined in a parent element using bindings.
Upvotes: 1
Reputation: 7325
I suppose you wanted bind converter object to the binding's Converter
property.
You can't bind to the binding's Converter
property since it is not a ´DependencyProperty´. You can acces a resource object and bind it e.g. to the ´Tag´, but it doesn't solve your problem:
<ComboBox MinWidth="270" Margin="0,0,5,5"
ItemsSource="{Binding Path=Demos, RelativeSource={RelativeSource AncestorType={x:Type local:DemoManager}}}"
SelectedValue="{Binding Path=CurrentStrategy, Converter={ ????}, Mode=TwoWay}"
Tag="{Binding Path='Resources[demoManagerConverter]', RelativeSource={RelativeSource AncestorType={x:Type localFrameworkDemo:usercontrol1View}}}"
IsEnabled="{Binding CanRefreshExecutionList, ElementName=Instance}"
DropDownOpened="StrategyComboBox_DropDownOpened">
If object is nested, you could just set(not bind) the Converter to the resource object:
Converter = {StaticResource demoManagerConverter}
Upvotes: 0