如何在Windows Phone中显示和折叠stackpanel? [英] How to visible and collapsed for stackpanel in windows phone?
问题描述
您好我使用两个堆栈面板,一个是在用户登录之前,第二个是在用户登录之后。如果用户在登录前显示stackpane 1并且用户登录后想要显示stackpanel 2.所以我必须显示并隐藏堆栈面板。
Hi I am using two stack panels one is before user login and second one is after user login. If user before login show stackpane 1 and if user logged in want to show stackpanel 2. So i have to do show and hide stack panels.
推荐答案
你好我有一个样品给你,请你参考
Hi I have a sample for you you please refer it
这里是xaml代码MainPage.xaml
here is xaml code MainPage.xaml
<phone:PhoneApplicationPage
x:Class="stackpannel1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- LOCALIZATION NOTE:
To localize the displayed strings copy their values to appropriately named
keys in the app's neutral language resource file (AppResources.resx) then
replace the hard-coded text value between the attributes' quotation marks
with the binding clause whose path points to that string name.
For example:
Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"
This binding points to the template's string resource named "ApplicationTitle".
Adding supported languages in the Project Properties tab will create a
new resx file per language that can carry the translated values of your
UI strings. The binding in these examples will cause the value of the
attributes to be drawn from the .resx file that matches the
CurrentUICulture of the app at run time.
-->
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"/>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.RowSpan="2" HorizontalAlignment="Left" Width="480">
<Button Content="Click Me" HorizontalAlignment="Left" Margin="156,0,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.133,0.107" Click="Button_Click"/>
</Grid>
<StackPanel x:Name="s1" Margin="0,62,0,220" Grid.Row="1" Background="#FF4191BF" >
<TextBlock Text="Stack Pannel 1" Name="t1" />
</StackPanel>
<StackPanel />
<StackPanel x:Name="s2" Margin="0,62,0,220" Grid.Row="1" Background="#FFB42DDC" >
<TextBlock Text="Stack Pannel 2" Name="t2" />
</StackPanel>
<StackPanel />
<!--Uncomment to see an alignment grid to help ensure your controls are
aligned on common boundaries. The image has a top margin of -32px to
account for the System Tray. Set this to 0 (or remove the margin altogether)
if the System Tray is hidden.
Before shipping remove this XAML and the image itself.-->
<!--<Image Source="/Assets/AlignmentGrid.png" VerticalAlignment="Top" Height="800" Width="480" Margin="0,-32,0,0" Grid.Row="0" Grid.RowSpan="2" IsHitTestVisible="False" />-->
</Grid>
</phone:PhoneApplicationPage>
和corespondin c#代码是MainPage.cs
and the corespondin c# code is MainPage.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using stackpannel1.Resources;
namespace stackpannel1
{
public partial class MainPage : PhoneApplicationPage
{
int i = 1;
// Constructor
public MainPage()
{
InitializeComponent();
s1.Visibility = Visibility.Visible;
s2.Visibility = Visibility.Collapsed;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (i == 2)
{
s1.Visibility = Visibility.Visible;
s2.Visibility = Visibility.Collapsed;
i=1;
}
else
{
s1.Visibility = Visibility.Collapsed;
s2.Visibility = Visibility.Visible;
i=2;
}
}
}
}
在这里你可以隐藏和显示堆栈panne usin visibility property
Here you can hide and show stack panne usin visibility property
s1.Visibility = Visibility.Visible。
s1.Visibility=Visibility.Visible.
其中s1是堆栈面板的名称
where s1 is the name of stack pannel
这篇关于如何在Windows Phone中显示和折叠stackpanel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!