I have the following Custom Control that uses a DataTemplate and is Bound to
a LightBox object. The template does bind correctly to properties directly on
the LightBox object. However my LightBox has a list of Lights and I want to
bind the List of lights in the DataTemplate somehow?
My attempt to solve the problem was to create a custom control that defined
a depencency property and set the dependency property in the DataTemplate. It
is located in the following xaml as "<custom:LightArrayControl" and the
dependency property is named LightBoxSource. The problem with this is that
the property does not get set. It executes the constructor of the control as
well as executing the RegisterDepencencyProperty method but never sets the
property itself. If I put a break point on the Property in the LightBox
object that I am trying to attach the DependencyProperty to it does break
there but the DependencyProperty does not break. This is confusing because
the only place that the property in the LightBox object would get called is
where I try to set my dependencyProperty equal to it in the XAML.
Any help would be appreciated.
<UserControl x:Class="StevenDale.MDAlertManager.Client.LightBox RowControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:StevenDale.MDAlertSystem.LightSystem;ass embly=StevenDale.MDAlertSystem"
xmlns:custom="clr-namespace:StevenDale.MDAlertManager.Client.UserCon trols.LightBoxControls"
Height="30" Width="536">
<UserControl.Resources>
</UserControl.Resources>
<UserControl.ContentTemplate>
<DataTemplate DataType="{x:Type src:LightBox}">
<StackPanel Orientation="Horizontal" Name="_lightBoxRow" >
<Image Name="_connectedImage" Margin="6,0,20,0"
Source="Images/bullet_ball_glass_red.png" Stretch="None" />
<TextBlock FontWeight="Bold" Margin="0,0,30,0"
VerticalAlignment="Center" HorizontalAlignment="Center"
Name="_lightIPAddress" Text="{Binding Path=IPAddress}" />
<custom:LightArrayControl Name="_lightArrayControl"
LightBoxSource="{Binding Path=Self}"
Initialized="LightArrayControl_Initialized" />
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsConnected}"
Value="True">
<Setter TargetName="_connectedImage" Property="Source"
Value="Images/bullet_ball_glass_red.png" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</UserControl.ContentTemplate>
</UserControl>