2

I wanted to standardize popup in my application. So I created a user control for it and reference it as follow:

    <!--<Popup x:Name="LoginPopup" Grid.ColumnSpan="2" Grid.RowSpan="2" Height="768" Width="1366" IsOpen="False">-->
        <uc:StandardDialog Name="StandardDialog" Height="768" Width="1366" Grid.ColumnSpan="2">
            .
            .
            .
        </uc:StandardDialog>
    <!--</Popup>-->

And in the code behind:

    private void LoginClicked(object sender, RoutedEventArgs e)
    {
        StandardDialog.IsOpen = true;
        //LoginPopup.IsOpen = true;
    }

    private void CloseLoginPopup(object sender, RoutedEventArgs e)
    {
        StandardDialog.IsOpen = false;
        //LoginPopup.IsOpen = false;
    }

However this failed with the following error, which points to the lines above:

Error 1 The name 'StandardDialog' does not exist in the current context C:\NSyncHg\MyApp.WinRT\Views\TestVisualAwarePage.xaml.cs 46 13 MyApp.WinRT

However if I were to uncomment the popup above and revert to the built in pop-up, everything compiles and run.

What am I doing wrong?

4

1 回答 1

6

You need to use the x:Name attribute, not just Name.

 <uc:StandardDialog x:Name="StandardDialog" ...

Windows Store applications don't automatically create a field for objects with their Name specified. The x:Name attribute is required if you want a named field to be created and available to the code behind.

于 2013-07-11T21:26:01.753 回答