简体   繁体   中英

c# missing sender object reference on click event handler

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:

在此输入图像描述

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM