【问题标题】:How to open Popup by clicking on grid view item in windows store app?如何通过单击 Windows 商店应用程序中的网格视图项打开弹出窗口?
【发布时间】:2015-05-04 12:20:42
【问题描述】:

我想通过单击 gridView 元素中的按钮打开弹出窗口,在弹出窗口中我有三个选项,通过单击该选项我想导航到具有元素 ID 的另一个页面

我想在 gridView 元素内单击按钮打开弹出窗口,我的代码如下所示:-

<GridView x:Name="Test" Grid.Row="1" Margin="20,20,20,20" >
        <GridView.ItemTemplate>
            <DataTemplate>
                <Grid HorizontalAlignment="Left" Width="250" Height="250">
                    <Button Background="Red" HorizontalAlignment="Left" VerticalAlignment="Top" Height="100" Content="OpenPopup" Click="Button_PointerPressed"></Button>                     
                    <Popup x:Name="Mypopup">
                        <TextBlock Text="hi"/>
                    </Popup>                    
                    <StackPanel VerticalAlignment="Bottom" Background="{ThemeResource ListViewItemOverlayBackgroundThemeBrush}">
                        <TextBlock Text="{Binding Title}" Foreground="{ThemeResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource TitleTextBlockStyle}" Height="60" Margin="15,0,15,0"/>
                        <TextBlock Text="{Binding Subtitle}" Foreground="{ThemeResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource CaptionTextBlockStyle}" TextWrapping="NoWrap" Margin="15,0,15,10"/>
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </GridView.ItemTemplate>
    </GridView>

点击事件

 private void Button_PointerPressed(object sender, RoutedEventArgs e)
    {

        Mypopup.isopen = true;

    }

错误:-当前上下文中不存在名称“Mypopup”

我是新手..所以帮助我

【问题讨论】:

    标签: c# xaml windows-store-apps


    【解决方案1】:

    您所要做的就是在 gridview 按钮的Onclick 事件上执行以下代码:

    popup.isopen = true
    

    然后在弹出窗口中,如果您想导航到另一个页面,您所要做的就是在适当的事件上使用Navigate

    Frame.Navigate(typeof(YourPage),YourID);
    

    编辑:如果您的 gridview 中的按钮是通过代码添加的,并且您想对这些按钮执行事件,请确保它们具有不同的名称,例如:GrdButton1/GrdButton2,然后给它们an event dynamicly

    如果它们被添加到 XAML 中,那么只需在其中添加一个事件

    <Button x:Name="ButtonTest"
            Click="ButtonTest_Click"/>
    

    如果这些都不能回答您的问题,请添加更多详细信息

    【讨论】:

    • thnx micbobo 。我正在使用 PointerPressed 事件。它不工作....我的朋友告诉我不要在 Windows 商店应用程序中使用点击事件....这是最好的请指导我...
    • 错误:- 当前上下文中不存在名称“Mypopup”......怎么办???
    • @DineshTomer 你弄明白了吗?
    猜你喜欢
    • 1970-01-01
    • 2014-04-19
    • 2018-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    相关资源
    最近更新 更多