简体   繁体   English

如何在特定的数据透视表项中叠加弹出窗口

[英]How to Overlay a Popup in a Specific Pivot Item

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). 这是一个有趣的问题,但是我只想在我的PivotPage中的单个PivotItem上以及仅在发生一定数量的“事件”(事件是单击事件,例如单击50次)之后才将弹出窗口覆盖。 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? 我的PivotItem中有一个ListBox,但我想知道在满足条件后如何在其上覆盖弹出窗口?

XAML 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). 另外,我将需要以某种方式检索弹出窗口的结果值(从“确定”或“取消”按钮),并根据该结果调用ApplySelectedEffectAndSaveAsync()方法或返回到上一个PivotItem(或上一个页面)。 The PivotItem with the overlay is actually index 1 and there is another PivotItem before it with index of 0. 带有叠加层的PivotItem实际上是索引1,而它前面还有另一个PivotItem,索引为0。

It seems like you are looking for MessageBox.Show . 似乎您正在寻找MessageBox.Show This method shows a popup with your own caption, text and either an OK or OK and cancel buttons. 此方法显示一个带有您自己的标题,文本以及“确定”或“确定”和“取消”按钮的弹出窗口。 The method returns a MessageBoxResult value which is either MessageBoxResult.OK or MessageBoxResult.Cancel . 该方法返回一个MessageBoxResult值,该值为MessageBoxResult.OKMessageBoxResult.Cancel

This is how it should be implemented in your code: 这是应该在您的代码中实现的方式:

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"
        } 
    }
<phone:PivotItem ...>
    <Grid>
        <ListBox .../>
        <Popup Name="MyPopup" IsOpen="false"/>
    </Grid>
</phone:PivotItem>

And you manage MyPopup from code behind (you count the clicks or events and set MyPopup.IsOpen = true ) 然后,您可以通过后面的代码来管理MyPopup(计算点击次数或事件并设置MyPopup.IsOpen = true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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