这里我试图在页面上点击按钮时看到堆栈面板。页面使用框架导航。 这是我的代码
login.page xaml
<StackPanel Panel.ZIndex="2" Name="pnlLeftMenu" Orientation="Horizontal" Margin="0,0,-192,0" Width="227" HorizontalAlignment="Right" Visibility="Collapsed" >
<StackPanel.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF458B85"/>
<GradientStop Color="#FF458B85" Offset="0.564"/>
</LinearGradientBrush>
</StackPanel.Background>
<Grid Width="25">
<Image Height="30" Margin="8,0,-9,0" VerticalAlignment="Top" Stretch="None" Source="Images/menu61.png" MouseDown="Image_MouseDown"/>
</Grid>
<Grid Width="200" >
<Grid.RowDefinitions>
<RowDefinition Height="31*"/>
<RowDefinition Height="68*"/>
<RowDefinition Height="178*"/>
<RowDefinition Height="43*"/>
</Grid.RowDefinitions>
<!--<Border Grid.Row="1" Background="Blue" Margin="10,0,0,0"/>-->
<Border Grid.Row="1" RenderTransformOrigin="0,1" BorderThickness="1,0" CornerRadius="50" Background="Blue" HorizontalAlignment="Left" Width="55" Height="55" VerticalAlignment="Top" Margin="10,0,0,0">
<Image Source="Images/user.png" Height="35"/>
</Border>
<Label Grid.Row="1" Content="Administrator" Width="130" Height="40" FontWeight="Bold" Foreground="White" FontSize="18" Margin="70,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Border Name="homeBorder" Grid.Row="2" Width="180" Height="30" Cursor="Hand" Margin="10,10,10,0" VerticalAlignment="Top" >
<Border.Style>
<Style>
<Setter Property="Border.Background" Value="#00cc66"/>
<Style.Triggers>
<Trigger Property="Border.IsMouseOver" Value="True">
<Setter Property="Border.Background" Value="#006633"/>
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<Label Content="Home" Margin="10,0,10,0" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Foreground="White"/>
</Border>
</Grid>
</StackPanel>
我的c#代码
public partial class Login : Page
{
public Login()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
MainWindow window = new MainWindow();
window.pnlLeftMenu.Visibility = System.Windows.Visibility.Visible;
Home hPage = new Home();
this.NavigationService.Navigate(hPage);
}
}
请帮帮我。
答案 0 :(得分:2)
您需要将MainWindow的引用传递给Login页面:
public partial class Login : Page
{
MainWindow _window;
public Login(MainWindow window)
{
InitializeComponent();
_window = window;
}
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
_window.pnlLeftMenu.Visibility = System.Windows.Visibility.Visible;
Home hPage = new Home();
this.NavigationService.Navigate(hPage);
}
}