代码之家  ›  专栏  ›  技术社区  ›  You-sheng Liang

StackPanel在WPF和xaml中显示布局中的框架

  •  0
  • You-sheng Liang  · 技术社区  · 7 年前

    我在一个DockPanel中创建了一个4堆栈面板

    哪个面板只是一个框架窗口

    4 StackPanel

    然后我创建一个网格,包括左StackPanel和右StackPanel 3 StackPannel

    现在,我在底部框架中添加了一个按钮,以切换隐藏左侧和右侧

    并显示VCenter帧或反转。但我不知道要做这个功能。

    有人给我建议吗?

    <Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="PanelUserCtrlSample.MainWindow"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <DockPanel LastChildFill="True">
        <StackPanel DockPanel.Dock="Top" Width="Auto" Height="50" Background="Red">
            <Frame x:Name="frmMainTop" NavigationUIVisibility="Hidden">
            </Frame>
        </StackPanel>
        <StackPanel DockPanel.Dock="Bottom" Width="Auto" Height="50" Background="Blue">
            <Frame x:Name="frmMainBottom" NavigationUIVisibility="Hidden">
            </Frame>
        </StackPanel>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="83*"/>
                <ColumnDefinition Width="434*"/>
            </Grid.ColumnDefinitions>
    
            <!--Full Screen-->
    
            <!--<StackPanel  DockPanel.Dock=""  Grid.ColumnSpan="2" Width="Auto" Height="Auto" Background="Black">
                <Frame x:Name="frmMainFull" NavigationUIVisibility="Hidden">
    
                </Frame>
            </StackPanel>-->
    
            <!--VCenter-->
            <StackPanel  DockPanel.Dock="Left"  Grid.ColumnSpan="2" Width="Auto" Height="Auto" Background="Black">
                <Frame x:Name="frmMainVCenter" NavigationUIVisibility="Hidden">
    
                </Frame>
            </StackPanel>
    
            <!--left-->
            <StackPanel  DockPanel.Dock="Left"  Grid.Column="0" Width="Auto" Height="Auto" Background="Green">
                <Frame x:Name="frmMainLeft" NavigationUIVisibility="Hidden">
    
                </Frame>
            </StackPanel>
    
            <!--Right-->
            <StackPanel Grid.Column="1" Background="Pink">
                <Frame x:Name="frmMainRight" NavigationUIVisibility="Hidden">
    
                </Frame>
            </StackPanel>
        </Grid>
    </DockPanel>
    

    主窗口_已加载

    private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            frmMainTop.NavigationService.Navigate(new PageTop1());
            frmMainLeft.NavigationService.Navigate(new PageLeft1());
            frmMainRight.NavigationService.Navigate(new PageRight1());
            frmMainBottom.NavigationService.Navigate(new PageBottom1());
        }
    

    文件列表

    enter image description here

    如果我想创建一个完整的stackpanel,我该如何实现它。

    1 回复  |  直到 7 年前
        1
  •  0
  •   You-sheng Liang    7 年前

    我找到了实现的解决方案。

    MainWindow rootwindow = (MainWindow)Application.Current.MainWindow;
    rootwindow.spMainLeft.Visibility = Visibility.Hidden;
    rootwindow.spMainRight.Visibility = Visibility.Hidden
    rootwindow.pageBottom.lblBottom.Content = "Change";