更改网格可见性属性

时间:2016-10-08 17:36:33

标签: c# visual-studio uwp

我为UWP编写应用程序。

我有这个xaml:

    <ScrollViewer HorizontalAlignment="Left" Height="668" Margin="63,52,0,0" VerticalAlignment="Top" Width="350">
        <GridView   x:Name="OrdersGridView" IsItemClickEnabled="True" >
            <GridView.ItemTemplate>
                <DataTemplate>
                    <StackPanel >
                        <Grid  Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,1,1">
                            <TextBlock Text="{Binding date_created}"  HorizontalAlignment="Left" TextAlignment="Center" TextWrapping="Wrap"  VerticalAlignment="Top" Width="350" Height="50" FontFamily="SF UI Display" FontSize="25" FontWeight="Light" Foreground="White" />
                            <TextBlock  TextAlignment="Center"  HorizontalAlignment="Left" Margin="0,146,-1,0" TextWrapping="Wrap" Text="{Binding billing.address_1}" VerticalAlignment="Top" Height="58" Width="350" FontFamily="SF UI Display" FontSize="25" FontWeight="Light" Foreground="White" />
                            <TextBlock  HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="{Binding billing.first_name}" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="25" FontWeight="Light" Foreground="White" Padding="0,0,0,0"/>

                        </Grid>

                    </StackPanel>
                </DataTemplate>
            </GridView.ItemTemplate>
        </GridView>
    </ScrollViewer>
    <Grid x:Name="DetailGrid" HorizontalAlignment="Left" Height="667" Margin="415,53,-2,0" VerticalAlignment="Top" Width="867">
        <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="390,172,0,0" VerticalAlignment="Top"/>


    </Grid>





</Grid>

我将DetailGrid.Visibility = Visibility.Collapsed设置为<Grid x:Name="DetailGrid"

中的此网格.cs

当我点击GridView中的元素时,我需要将其更改为Visible

我怎么做?

感谢他们的帮助。

2 个答案:

答案 0 :(得分:0)

我找到了问题的答案

这是xaml:

   <GridView   x:Name="OrdersGridView" IsItemClickEnabled="True"

          SelectionMode="Single" ItemClick="OrdersGridView_ItemClick" 
           >
            <GridView.ItemTemplate>
                <DataTemplate>
                    <StackPanel >
                        <Grid x:Name="GridInf" Tapped="Grid_Tapped"  Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,1,1">
                            <TextBlock Text="{Binding date_created}"  HorizontalAlignment="Left" TextAlignment="Center" TextWrapping="Wrap"  VerticalAlignment="Top" Width="350" Height="50" FontFamily="SF UI Display" FontSize="25" FontWeight="Light" Foreground="White" />
                            <TextBlock  TextAlignment="Center"  HorizontalAlignment="Left" Margin="0,146,-1,0" TextWrapping="Wrap" Text="{Binding billing.address_1}" VerticalAlignment="Top" Height="58" Width="350" FontFamily="SF UI Display" FontSize="25" FontWeight="Light" Foreground="White" />
                            <TextBlock  HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="{Binding billing.first_name}" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="25" FontWeight="Light" Foreground="White" Padding="0,0,0,0"/>

                        </Grid>

                    </StackPanel>
                </DataTemplate>
            </GridView.ItemTemplate>
        </GridView>
    </ScrollViewer>
    <Grid x:Name="DetailGrid" HorizontalAlignment="Left" Height="667" Margin="415,53,-2,0" VerticalAlignment="Top" Width="867">
        <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="390,172,0,0" VerticalAlignment="Top"/>


    </Grid>

以下是活动代码:

 private void Grid_Tapped(object sender, TappedRoutedEventArgs e)
    {
        DetailGrid.Visibility = Visibility.Visible;
    }

答案 1 :(得分:0)

这就是我这样做的方式:

XAML:添加选择更改的事件处理程序

<ScrollViewer HorizontalAlignment="Left" Height="668" Margin="63,52,0,0" VerticalAlignment="Top" Width="350">
        <GridView   x:Name="OrdersGridView" IsItemClickEnabled="True" Selection_Changed="OrdersGridView_SelectionChanged">
            <GridView.ItemTemplate>
                <DataTemplate>
                    <StackPanel >
                        <Grid  Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,1,1">
                            <TextBlock Text="{Binding date_created}"  HorizontalAlignment="Left" TextAlignment="Center" TextWrapping="Wrap"  VerticalAlignment="Top" Width="350" Height="50" FontFamily="SF UI Display" FontSize="25" FontWeight="Light" Foreground="White" />
                            <TextBlock  TextAlignment="Center"  HorizontalAlignment="Left" Margin="0,146,-1,0" TextWrapping="Wrap" Text="{Binding billing.address_1}" VerticalAlignment="Top" Height="58" Width="350" FontFamily="SF UI Display" FontSize="25" FontWeight="Light" Foreground="White" />
                            <TextBlock  HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="{Binding billing.first_name}" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="25" FontWeight="Light" Foreground="White" Padding="0,0,0,0"/>

                        </Grid>

                    </StackPanel>
                </DataTemplate>
            </GridView.ItemTemplate>
        </GridView>
    </ScrollViewer>

和c#代码:

private void OrdersGridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    DetailGrid.Visibility = Visibility.Visible;
}