0

This is an interesting question, but I would like to overlay a popup only on a single PivotItem within my PivotPage, and only after a certain number of 'events' occurs (the events being a click event, say 50 times clicked). I have in my PivotItem a ListBox, but I am wondering how after my condition is met that I can overlay a popup over it?

XAML

<phone:PivotItem Header="{Binding Path=LocalizedResources.EditPage_Header_Effects, Source={StaticResource LocalizedStrings}}">

            <ListBox Name="ListBoxEffects" SelectionMode="Single" ItemsSource="{Binding}" Margin="{Binding}"
                     toolkit:TiltEffect.IsTiltEnabled="True" SelectionChanged="ListBox_SelectionChanged" >
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <toolkit:WrapPanel ItemWidth="146" />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical" Margin="12,0,0,24" >
                            <Image Source="{Binding Thumbnail}" Width="134" Height="134" />
                            <TextBlock Text="{Binding Name}" TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeNormal}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

        </phone:PivotItem>

Code Behind

private void BuildLocalizedApplicationBar()
    {
        // Set the page's ApplicationBar to a new instance of ApplicationBar.
        ApplicationBar = new ApplicationBar();

        ApplicationBarIconButton saveButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/save.png", UriKind.Relative));
        saveButton.Text = AppResources.EditPage_ApplicationBar_Save;
        saveButton.Click += saveButton_Click;
        ApplicationBar.Buttons.Add(saveButton);
    }

    void saveButton_Click(object sender, EventArgs e)
    {
        Settings.SavedCount.Value += 1;
        if(Settings.SavedCount.Value > 50)
            //Display Popup

        ApplySelectedEffectAndSaveAsync();
    }

Also, I would need to somehow retrieve the resulting value of the popup (From an OK or Cancel button), and depending on that result either call the ApplySelectedEffectAndSaveAsync() method or return to the previous PivotItem (or previous page). The PivotItem with the overlay is actually index 1 and there is another PivotItem before it with index of 0.

4

2 回答 2

0
<phone:PivotItem ...>
    <Grid>
        <ListBox .../>
        <Popup Name="MyPopup" IsOpen="false"/>
    </Grid>
</phone:PivotItem>

并且您从后面的代码管理 MyPopup(您计算点击或事件并设置MyPopup.IsOpen = true

于 2013-10-12T16:46:58.283 回答
0

看来您正在寻找MessageBox.Show. 此方法显示一个带有您自己的标题、文本以及 OK 或 OK 和取消按钮的弹出窗口。该方法返回一个MessageBoxResult值,要么是MessageBoxResult.OK要么MessageBoxResult.Cancel

这就是它应该在您的代码中实现的方式:

private void BuildLocalizedApplicationBar()
    {
        // Set the page's ApplicationBar to a new instance of ApplicationBar.
        ApplicationBar = new ApplicationBar();

        ApplicationBarIconButton saveButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/save.png", UriKind.Relative));
        saveButton.Text = AppResources.EditPage_ApplicationBar_Save;
        saveButton.Click += saveButton_Click;
        ApplicationBar.Buttons.Add(saveButton);
    }

    void saveButton_Click(object sender, EventArgs e)
    {
        Settings.SavedCount.Value += 1;
        if(Settings.SavedCount.Value > 50)
        {
            if(MessageBox.Show("Message", "Title", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                // Action for "OK"
            else 
                // Action for "Cancel"
        } 
    }
于 2013-10-10T18:36:13.953 回答