简体   繁体   English

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

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

I have the following XAML markup, which I am using to display the GUI of my C# application: 我有以下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>

The above markup is nested inside the following structure at the top of the file: 上面的标记嵌套在文件顶部的以下结构内:

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

Later in the file, I have the following markup: 在文件的后面,我有以下标记:

                    </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>

This XAML displays the following GUI: 此XAML显示以下GUI:

调整大小前的应用窗口

As you can see from the image, the 'main content' of the page is overlapping the <StackPanel> where I have added buttons for the navigation, and other features of my application (back, refresh, etc). 从图像中可以看到,页面的“主要内容”与<StackPanel>重叠,在其中我添加了导航按钮和应用程序的其他功能(上一步,返回等)。

I can resize the window, by dragging one of the corners, and adjust it so that the buttons and other features are all displayed correctly: 我可以通过拖动一个角来调整窗口的大小,并对其进行调整,以使按钮和其他功能都可以正确显示:

菜单栏的预期布局

However, it is also possible to resize the window too much (ie make it too large), which causes too much white space to be displayed between these buttons and things, and also causes the images on the far right hand side to be moved to a different location than the one I had intended: 但是,也可能将窗口的大小调整得太大(即使其过大),这将导致在这些按钮和事物之间显示过多的空白,并且还会导致最右边的图像移动到与我原先打算的地点不同:

过度扩展的菜单栏

The images on the far right hand side of my application window are the ones displayed by the XAML markup in the third bit of code that I have copied into my question. 我的应用程序窗口最右边的图像是XAML标记在我复制到问题中的第三部分代码中显示的图像。

So, my question is- is there a way that I can 'fix' the size of the <StackPanel> , <Grid> , <Style> or header of the <TabPanel> where I am displaying the navigation buttons and other images so that they're not resized with the rest of the window when the user drags one of the corners of the window around? 所以,我的问题是-有一种方法可以“固定” <StackPanel><Grid><Style><TabPanel>标头的大小,以便在其中显示导航按钮和其他图像,以便当用户拖动窗口的某个角落时,它们是否不会与窗口的其余部分一起调整大小?

I tried setting the Height property of the <TabControl> to a specific value (eg 50), but this caused the whole content of the <TabControl> to shrink to 50... ie all of the content of the window was then displayed in an area on the window that was only 50 pixels high... 我尝试将<TabControl>Height属性设置为特定值(例如50),但是这导致<TabControl>的整个内容缩小到50 ...即,然后将窗口的所有内容显示在窗口上只有50像素高的区域...

Basically, I want the content that I have shown here to remain the same no matter how the user interacts with the application, and only the content displayed below this to be updated dynamically as the user interact with the application. 基本上,无论用户如何与应用程序交互,我都希望此处显示的内容保持不变,并且仅显示在此下方的内容可以在用户与应用程序交互时动态更新。 Anyone have any suggestions? 有人有什么建议吗?

Try setting the height of row 1 from 0.05* to Auto! 尝试将第1行的高度从0.05 *设置为“自动”! That should solve the overlap issue. 那应该解决重叠问题。

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

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