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

时间:2013-10-10 16:57:50

标签: c# windows-phone-7 windows-phone-8 popup

这是一个有趣的问题,但我想在我的数据透视表中仅在一个数据透视图上覆盖一个弹出窗口,并且仅在发生一定数量的“事件”之后(事件是点击事件,比如点击50次) 。我在我的PivotItem中有一个ListBox,但是我想知道在满足条件之后我可以覆盖一个弹出窗口吗?

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>

背后的代码

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();
    }

另外,我需要以某种方式检索弹出窗口的结果值(从“确定”或“取消”按钮),并根据该结果调用ApplySelectedEffectAndSaveAsync()方法或返回上一个PivotItem(或上一页) )。带有叠加层的PivotItem实际上是索引1,并且在索引为0之前还有另一个PivotItem。

2 个答案:

答案 0 :(得分:0)

好像你正在寻找MessageBox.Show。此方法显示一个弹出窗口,其中包含您自己的标题,文本以及“确定”或“确定”和“取消”按钮。该方法返回MessageBoxResultMessageBoxResult.OKMessageBoxResult.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"
        } 
    }

答案 1 :(得分:0)

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

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

相关问题