【问题标题】:Re-size page inside window WPF在窗口 WPF 内重新调整页面大小
【发布时间】:2014-01-03 07:14:08
【问题描述】:

我有一个窗口,里面有一个 tabcontrol,每个 tabitem 都有一个框架,它绑定到一个页面对象。但我似乎无法调整框架/页面大小以适应“主窗口”。这是我的代码:

<controls:MetroWindow x:Class="Mplayer.MainWindow"
                  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                  Title="Mplayer" 
                  Initialized="Window_Initialized" Height="770" Width="1125">


<TabControl HorizontalAlignment="Left" Height="45" VerticalAlignment="Top" Width="1125" Margin="0,0,0,0">
    <TabItem Header="Home" x:Name="HomeTab">
        <TabItem.Content>
            <Frame Source="HomePage.xaml" Margin="0,0,7,-697"/>
        </TabItem.Content>
    </TabItem>
</TabControl>


</controls:MetroWindow>

这里是“HomePage.xaml”

<Page x:Class="Mplayer.HomePage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  mc:Ignorable="d" 
  Height="770" Width="1125"
Title="HomePage" Foreground="Black">

<Grid Background="#373737">
    <Grid Background="#585858" HorizontalAlignment="Left" Width="400"/>
</Grid>
</Page>

希望您能理解我的问题,并在此先感谢:)

【问题讨论】:

    标签: c# wpf xaml


    【解决方案1】:

    从页面定义以及 TabControl 定义中删除硬编码的高度和宽度

    Height="770" Width="1125"
    

    【讨论】:

    • 啊,它本身并没有完成这项工作,但显然我必须使 tabcontrol 本身更大并​​适合整个屏幕。那是问题的原因..但是感谢您的帮助:)
    • 另外,为什么还要在 TabControl 上设置硬编码的 widthheight?也删除它,让 WPF 窗口自动适应它。 TabControl 将占用 Window 的大小。
    【解决方案2】:

    您明确设置 TabControl 和 HomePage 的高度和宽度。删除 Page 和 TabControl 中的这些值。

      <TabControl>
        <TabItem Header="Home" x:Name="HomeTab">
            <Frame Source="HomePage.xaml"/>            
        </TabItem>
      </TabControl>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-29
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      • 2018-09-25
      相关资源
      最近更新 更多