I've created a silverlight app with a DeepEarth map control on it. Here is my base XAML
<Grid x:Name="LayoutRoot" >
<!-- Map Control -->
<DeepEarth:Map x:Name="map" Margin="0,0,0,0">
<Controls:CoordControl VerticalAlignment="Bottom" HorizontalAlignment="Right" />
<Controls:ScaleControl VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="12,12,12,40" />
</DeepEarth:Map>
<Controls:NavControl x:Name="navControl" >
<StackPanel Orientation="Horizontal">
<Button x:Name="MyButton" Content="Hi" Click="MyButton_Click"></Button>
</StackPanel>
</Controls:NavControl>
</Grid>
I have a behaviour class I've created which I want to attach to the button
public Page()
{
InitializeComponent();
new ButtonActionWithCancel(MyButton, new CreatePointCommand(map));
}
void MyButton_Click(object sender, RoutedEventArgs e)
{
if (MyButton == null) throw new Exception("Wat?");
}
This is meant to do some stuff to MyButton, hook up some events and stuff. The problem is that MyButton is null at runtime. How come? Other controls in the hierarchy are not null. Whats going on?