c# missing sender object reference on click event handler

时间:2016-04-07 10:43:20

标签: c# wpf xaml windows-phone-8.1

I'm doing a WindowsPhone/Universall App based on a HupPage Template.

I'm pretty far developing this app and have implemented lately some app wide changes. So I don't know anymore what I've did to cause this error. It's my first WP project and kind of chaotic :-)

First I thought it was implementing a UserControl which really is a major part of the app. I gain some help in this post.

Now, I've noticed that every button I push, the Click_EventHandler function doesn't receive the sender object correctly. First I thought it was this UserControl implementation but then I've added a BasicPage1 (just a single Button in xaml) to the HupTemplate project and referenced it in the APP.xaml file.

Here is the code and screenshot:

app.xaml.cs

 if (!rootFrame.Navigate(typeof(BasicPage1), e.Arguments))
            {
                throw new Exception("Failed to create initial page");
            }

Basicpage1

 <Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,9.5,19,0">
            <Button x:Name="button" Content="Button" HorizontalAlignment="Left"  
                Grid.Row="1" VerticalAlignment="Top" Click="button_Click"/>
        </Grid>

And the BasicPage1 error:

enter image description here

What could possibly cause this error?

Idea #1: While implementing the UserControl I've added the behavioural SDK to the project.

Idea #2: Is it the change from HubPage --> BasicPage1 in the app.xaml.cs? I've added the BasicPage1 to both projects (WP & Store).

Cheers,

Chris

1 个答案:

答案 0 :(得分:0)

I would say that the problem is that sender is of another type. Debug to know, who is the sender.