0

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?

mcintyre321
  • 12,996
  • 8
  • 66
  • 103
  • is everything rendered correctly on the page? – Mike_G Feb 23 '09 at 22:12
  • Yep the button is visible and clicking it seems to work – mcintyre321 Feb 23 '09 at 23:15
  • Won't the sender in MyButton_Click be the button? So you can just do Button myLocalButton = (Button)sender, then do what you need to it? – mattmanser Feb 24 '09 at 14:11
  • Thats not really what I'm after. The long term goal is to have a StackPanel there in and I will dynamically add buttons for commands into it depending on the current app state. To do that I need to have a non null reference to control. – mcintyre321 Feb 25 '09 at 17:54
  • Could you phrase your question in Jeopardy form per the FAQ? It'd help us provide a clearer answer to folks. – Jeff Wilcox Aug 10 '09 at 20:20
  • Its actually stopped happenign. Maybe it was to do with the beta version... – mcintyre321 Aug 11 '09 at 11:34

1 Answers1

1

It stopped happening when I moved off the beta

mcintyre321
  • 12,996
  • 8
  • 66
  • 103