I have custom control with nested (custom) control. I would like to get the property from the nested control and pass it to converter of main control. Here is my code:
<Button.IsEnabled>
<MultiBinding Converter="{x:Static app:MainControl.CanExcludeConverter}">
<Binding Path="PageIndex" ElementName="nav_pane"/>
<Binding Path="History" />
</MultiBinding>
</Button.IsEnabled>
The second parameter is passed correctly, but the first one is not -- no matter what I do I get only DependencyProperty.UnsetValue. Firstly I had PageIndex as just property with notifiers, then I made it dependency property, then I tried several ways to set the Binding -- no success at all.
"nav_pane" is the name of my custom control which is nested in MainControl. PageIndex is dependency property of NavPane.
What am I missing?
Edits
1
Longer example. MainControl actually consists of NavPane and that's all :-) Thanks to the dependency properties set in NavPane as "slots" I can add new controls within frame (rectangle) of NavPane. So this is how it starts:
<UserControl x:Class="Worture.MainControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:app="clr-namespace:Worture"
mc:Ignorable="d"
Height="Auto" Width="320"
BorderThickness="2" BorderBrush="Navy"
MouseEnter="UserControl_MouseEnter"
IsVisibleChanged="UserControl_IsVisibleChanged"
Loaded="UserControl_Loaded">
<Grid Margin="4,0,4,4">
<app:NavPane x:Name="nav_pane"
OnNavigation="UpdateNavPane">
<app:NavPane.UpperSlot>
<Button Margin="4,0,0,0">
<StackPanel Orientation="Horizontal">
<app:AutoGreyableImage Source="/Worture;component/Images/plus.png" Width="24" Height="24"/>
</StackPanel>
<Button.IsEnabled>
...
The rest is above.
2
Dependy property in NavPane.
public static readonly DependencyProperty PageIndexProperty =
DependencyProperty.Register(NameOf.Get((NavPane dlg) => dlg.PageIndex),
typeof(int?),
typeof(NavPane),
new UIPropertyMetadata(null));
public int? PageIndex
{
get { return (int?)GetValue(PageIndexProperty); }
set { SetValue(PageIndexProperty, value); }
}
NameOf is a nice class found on SO, which gets name of property, field, etc. Thanks to it, I avoid magical numbers and I am better suited for obfuscation.
3
I get UnsetValue as input argument in converter. PageIndex is set on various occasions (it depends on user too). But to focus, I set it (right now) to null as the first line in constructor. So theoretically I should get such argument -- null (as "int?").