Help needed. Button and Listbox "declared" in xaml is null in the code.
Hi all,
I need some help. My btn2 and Listbox are null and I have no idea what went wrong.
xaml:
<DockPanel>
<local:HSChart x:Name="chart" Width="820" Height="400"
ChartTitle="Graph 1: 24-hour blood pressure pattern"
YAxisTitle="Pressure (mmHg)"
SecondaryYAxisTitle="Pulse Rate (beats/min)"
DockPanel.Dock="Top"/>
.....
<Button x:Name="btn1" Grid.Row="0" Grid.Column="2" Content="Browse" Click="btn1_Click" />
<ListBox x:Name="BlockOneDataTable" Grid.Row="0" Grid.Column="3" Width="150" ItemsSource="{Binding BlockOne}"/>
<Button x:Name="btn2" Grid.Row="1" Grid.Column="2" Content="Browse" Click="btn2_Click"/>
<ListBox x:Name="BlockTwoDataTable" Grid.Row="1" Grid.Column="3" Width="150" ItemsSource="{Binding BlockTwo}"/>
</Grid>
</DockPanel>
and both BlockOne and BlockTwo are DependancyProperties:
public static DependencyProperty BlockOneProperties = DependencyProperty.Register("BlockOne", typeof(List<BPData>), typeof(Window1));
public static DependencyProperty BlockTwoProperties = DependencyProperty.Register("BlockTwo", typeof(List<BPData>), typeof(Window1));
public List<BPData> BlockOne
{
get { return (List<BPData>)GetValue(BlockOneProperties); }
set { SetValue(BlockOneProperties, value); }
}
.....
and
BPClass have the following declaration:
public class BPData : DependencyObject
{
#region Public Property
#region DateTimeProperty
public static DependencyProperty DateTimeProperty =
DependencyProperty.Register("DateTime", typeof(DateTime), typeof(BPData));
public DateTime DateTime {
get { return (DateTime)GetValue(DateTimeProperty) ; }
set { SetValue(DateTimeProperty, value); }
}
#endregion
#region SystolicProperty
public static DependencyProperty SystolicProperty =
DependencyProperty.Register("Systolic", typeof(int), typeof(BPData));
public int Systolic {
get { return (Int32)GetValue(SystolicProperty); }
set { SetValue(SystolicProperty, value); }
}
#endregion
......
I am now stuck in a strange problem.
When I click on btn1, the Click action is triggered and the PlotChart method is called, a the listbox will be populated with the data.
but when I clicked on btn2, nothing happened, why isn't the btn2_Click triggered (cos it null?? but why is it null when btn1 is worknig ) ?
<Button x:Name="btn2" Grid.Row="1" Grid.Column="2" Content="Browse" Click="btn2_Click"/>
Another issue is my BlockTwoDataTable is null in the PlotChart() method, whlist BlockOneDataTable is correctly reference to as a ListBox. Where did i go wrong?
I do a watch on this and was very shock to find the my btn2 and DataTableTwo is null.
:(
Thanks and Best Regards,
Zuff