繁体   English   中英

XAML-如何设置高度 <TabControl> 固定值?

[英]XAML- how to set the height of a <TabControl> to a fixed value?

我有以下XAML标记,用于显示C#应用程序的GUI:

<Grid x:Name="templateRoot" ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
    <Grid.ColumnDefinitions>
        <ColumnDefinition x:Name="ColumnDefinition0"/>
        <ColumnDefinition x:Name="ColumnDefinition1" Width="0"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition x:Name="RowDefinition0" Height="Auto"/>
        <RowDefinition x:Name="RowDefinition2" Height="0.05*"/>
        <RowDefinition x:Name="RowDefinition1" Height="*"/>
    </Grid.RowDefinitions>
    <TabPanel x:Name="headerPanel" Background="White" Grid.Column="0" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1" VerticalAlignment="Top"/>
    <StackPanel Grid.Row="1" Orientation="Horizontal" FlowDirection="RightToLeft">
    </StackPanel>
    <StackPanel Grid.Row="1" Orientation="Horizontal" FlowDirection="LeftToRight" Height="30" VerticalAlignment="Top">
        <Button Style="{DynamicResource NoChromeButton}" Click="backBtn_Click" Margin="0,0,0,0" HorizontalAlignment="Left" >
            <Image Source="C:\...\arrow_left.png" Height="30" Width="40" />
        </Button>
        <Button Style="{DynamicResource NoChromeButton}" Click="RefreshBtn_Click" Margin="0,0,0,0" HorizontalAlignment="Left" >
            <Image Source="C:\...\arrow_loop3.png" Height="30" Width="30" />
        </Button>
        <Button Style="{DynamicResource NoChromeButton}" Click="referThis" Margin="0,0,0,0" HorizontalAlignment="Left" HorizontalContentAlignment="Left" Height="30" Width="80">
            <TextBlock>Refer Patient</TextBlock>
        </Button>
    </StackPanel>
    <Border x:Name="contentPanel" BorderBrush="Green" BorderThickness="5" Background="{TemplateBinding Background}" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="2" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
        <ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
    </Border>
</Grid>

上面的标记嵌套在文件顶部的以下结构内:

<Window x:Class.... >
    <Window.Resources>
        <Style ...>
            ...
            <Setter Property="Template">
                <Setter.value>
                    <ControlTemplate TargetType="{x:Type TabControl}">
                        <!--(Above markup goes here) -->

在文件的后面,我有以下标记:

                    </ControlTemplate>
                </Setter.value>
            </Setter>
        </Style>
        ...
    </Window.Resources>
    <Grid Name = "grid">
        <Image x:Name="Connected" Source="...\abc.png" Height="50" Width="50" Margin="750, 0, -5, 640"></Image>
        <!-- A few more image tags here -->
        <TabControl ... >
            <!-- XML for each of the tab items & their content here -->
        </TabControl>
    </Grid>
</Window>

此XAML显示以下GUI:

调整大小前的应用窗口

从图像中可以看到,页面的“主要内容”与<StackPanel>重叠,在其中我添加了导航按钮和应用程序的其他功能(上一步,返回等)。

我可以通过拖动一个角来调整窗口的大小,并对其进行调整,以使按钮和其他功能都可以正确显示:

菜单栏的预期布局

但是,也可能将窗口的大小调整得太大(即使其过大),这将导致在这些按钮和事物之间显示过多的空白,并且还会导致最右边的图像移动到与我原先打算的地点不同:

过度扩展的菜单栏

我的应用程序窗口最右边的图像是XAML标记在我复制到问题中的第三部分代码中显示的图像。

所以,我的问题是-有一种方法可以“固定” <StackPanel><Grid><Style><TabPanel>标头的大小,以便在其中显示导航按钮和其他图像,以便当用户拖动窗口的某个角落时,它们是否不会与窗口的其余部分一起调整大小?

我尝试将<TabControl>Height属性设置为特定值(例如50),但是这导致<TabControl>的整个内容缩小到50 ...即,然后将窗口的所有内容显示在窗口上只有50像素高的区域...

基本上,无论用户如何与应用程序交互,我都希望此处显示的内容保持不变,并且仅显示在此下方的内容可以在用户与应用程序交互时动态更新。 有人有什么建议吗?

尝试将第1行的高度从0.05 *设置为“自动”! 那应该解决重叠问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM