How can I bind a control inside a usercontrol resource to a property? Alternatively, can I find the control from the code behind and get & set the value from there?
Here is my markup. I've stripped it down to just the relevant part:
Salesmen.xaml:
<UserControl.Resources>
<ControlTemplate x:Key="EditAppointmentTemplate1" TargetType="local:SchedulerDialog" x:Name="ControlTemplate">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Grid>
<Grid Name="grdTotal" Grid.Row="4" Visibility="{Binding ResourceTypesVisibility}">
<TextBox x:Name="totalSalesmen" Grid.Row="0" Grid.Column="1" Margin="3" Width="120" Text="{Binding Parent.totalSalesmen, ElementName=LayoutRoot, Mode=TwoWay}" />
</Grid>
</ScrollViewer>
</ControlTemplate>
<Style x:Key="EditAppointmentDialogStyle1" TargetType="local:SchedulerDialog">
<Setter Property="Template" Value="{StaticResource EditAppointmentTemplate1}" />
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Left" Margin="10,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" BorderBrush="Transparent">
<telerik:RadCalendar Name="RadCalendar" SelectedDate="{Binding CurrentDate, ElementName=RadScheduleViewTests, Mode=TwoWay}" IsTodayHighlighted="True"
telerik:StyleManager.Theme="Metro" HorizontalAlignment="Left" VerticalAlignment="Top" FirstDayOfWeek="Sunday" Margin="0,0,15,0"
SelectionChanged="RadCalendar_SelectionChanged_1" >
</telerik:RadCalendar>
</ScrollViewer>
</StackPanel>
<telerik:RadScheduleView Name="RadScheduleViewTests" MinAppointmentWidth="100" Tag="{Binding Path=Context, ElementName=TestDayPage}"
telerik:StyleManager.Theme="Metro" Grid.Column="1" EditAppointmentDialogStyle="{StaticResource EditAppointmentDialogStyle1}"
AppointmentCreating="RadScheduleViewTests_AppointmentCreating_1" AppointmentEditing="RadScheduleViewTests_AppointmentEditing_1"
AppointmentDeleting="RadScheduleViewTests_AppointmentDeleting_1" FirstDayOfWeek="Sunday" ShowDialog="RadScheduleViewTests_ShowDialog_1"
AppointmentEdited="RadScheduleViewTests_AppointmentEdited_1">
<telerik:RadScheduleView.DragDropBehavior>
<examiners:CustomDragDropBehaviour/>
</telerik:RadScheduleView.DragDropBehavior>
<telerik:RadScheduleView.SchedulerDialogHostFactory>
<test:CustomScheduleViewDialogHostFactory />
</telerik:RadScheduleView.SchedulerDialogHostFactory>
<telerik:RadScheduleView.ViewDefinitions>
<telerik:DayViewDefinition/>
<telerik:WeekViewDefinition/>
<telerik:MonthViewDefinition/>
<telerik:TimelineViewDefinition/>
</telerik:RadScheduleView.ViewDefinitions>
</telerik:RadScheduleView>
</Grid>
And here's my property. Despite the two-way binding it is always null:
Salesmen.xaml.cs:
string totalSalesmen { get; set; }
I've heard about the VisualTreeHelper and the LogicalTreeHelper. These might enable another approach - finding the control and getting and them manually. However, VisualTreeHelper only sees the LayoutRoot and it's children (not UserControl.Resources), and LogicalTreeHelper does not seem to be available (it's a SilverLight 5 project; I don't know what framework is used by Silverlight 5. I understand that LogicalTreeHelper is only available in 4.5 and later)
Thank you for you assistance. Note: this question will get a +50 bounty. The system requires me to wait for 2 days to put a bounty, so I will put the bounty and accept the answer after 2 days. I will let you know if your answer works before that.