繁体   English   中英

在WPF中调整ToolWindow和内容的大小

[英]Resizing of ToolWindow and contents in WPF

我们有VS扩展。 用户使用ToolWindowPane与扩展进行交互。 ToolWindowPane的高度和宽度取决于用户如何设置其VS环境,并且当前ToolWindowPane的内容未正确调整大小。

所以这是窗口:

public class SymCalculationUtilitiesWindow : ToolWindowPane
{
    /// <summary>
    /// Initializes a new instance of the <see cref="SymCalculationUtilitiesWindow"/> class.
    /// </summary>
    public SymCalculationUtilitiesWindow() : base(null)
    {
        this.Caption = "Sym Calculation Utilities";

        this.ToolBar = new CommandID(new Guid(Guids.guidConnectCommandPackageCmdSet), Guids.SymToolbar);
        // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
        // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
        // the object returned by the Content property.
        this.Content = new UtilitiesView();

    }

}

因此UtilitiesView是默认视图。 这是xaml:

<UserControl
         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"
         xmlns:local="clr-namespace:Sym.VisualStudioExtension" x:Class="Sym.VisualStudioExtension.Engines.UtilitiesView"
         xmlns:engines="clr-namespace:Sym.VisualStudioExtension.Engines" 
         Background="{DynamicResource VsBrush.Window}"
         Foreground="{DynamicResource VsBrush.WindowText}"
         mc:Ignorable="d"
         local:ViewModelLocator.AutoWireViewModel="True"
         x:Name="MyToolWindow" Height="800" Width="400">

<UserControl.Resources>
    <DataTemplate DataType="{x:Type engines:CalcEngineViewModel}">
        <engines:CalcEngineView/>
    </DataTemplate>
    <DataTemplate DataType="{x:Type engines:TAEngineViewModel}">
        <engines:TAEngineView/>
    </DataTemplate>
</UserControl.Resources>

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto" />
        <RowDefinition Height="207*" />
        <RowDefinition Height="593*"/>
    </Grid.RowDefinitions>
    <Grid x:Name="MainContent"
        Grid.Row="1" Grid.RowSpan="2">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <ContentControl Content="{Binding CurrentEngineViewModel}" Grid.RowSpan="2"/>
    </Grid>

</Grid>

并且用户做出选择以确定CurrentEngineViewModel。

以下是其中一个可能的CurrentEngineViewModel的xaml:

<UserControl x:Class="Sym.VisualStudioExtension.Engines.CalcEngineView"
         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"   
         xmlns:domain="clr-namespace:Sym.Engines.Calculation.Builder.Domain;assembly=Sym.Engines.Calculation" 
         xmlns:core="clr-namespace:Sym.Core.Domain;assembly=Sym.Core" 
         xmlns:helper="clr-namespace:Sym.VisualStudioExtension.Helper_Classes"
         xmlns:local="clr-namespace:Sym.VisualStudioExtension"           
         local:ViewModelLocator.AutoWireViewModel="True"
         mc:Ignorable="d"             
         d:DesignHeight="800" d:DesignWidth="400">
<UserControl.Resources>
    <ContextMenu>
        ...
    </ContextMenu>
</UserControl.Resources>
<Grid Margin="-20,-20,-20,-20">
    <Grid.RowDefinitions>
        <RowDefinition Height="8*"/>

    </Grid.RowDefinitions>
    <TabControl x:Name="tabControl" HorizontalAlignment="Left" Height="617" Margin="20,54,0,0" VerticalAlignment="Top" Width="357">
        <TabItem Header="Calculation Files">
            <ListBox Name="CalcFilesListBox" 
                     Margin="20" ItemsSource="{Binding CalcFilesList}"                           
                     ContextMenu="{StaticResource NewEditDeleteContextMenu}"
                     Tag="{x:Type core:CalcFile}">
                ...
            </ListBox>                
        </TabItem>
        <TabItem Header="Template Files" Height="22" VerticalAlignment="Top">
            <TreeView ItemsSource="{Binding TemplateFamilyList}" 
                      Margin="20"
                      ContextMenu="{StaticResource NewEditDeleteContextMenu}"
                      Tag="{x:Type domain:TemplateParameter}">
                <TreeView.Resources>
                    ...
                </TreeView.Resources>
            </TreeView>
        </TabItem>
        <TabItem Header="Advanced Calc Files">
            <ListBox Margin="20" 
                     ItemsSource="{Binding AdvancedCalcFilesList}"
                     ContextMenu="{StaticResource NewEditDeleteContextMenu}"
                     Tag="{x:Type domain:TemplateCalculation}">
                ...
            </ListBox>
        </TabItem>
    </TabControl>
    <Label x:Name="label" Content="{Binding Path=Title}" HorizontalAlignment="Left" Height="27" Margin="10,22,0,0" VerticalAlignment="Top" Width="367"/>
</Grid>

在我看来,在ToolWindowPane上,有一个Grid,在Grid上有另一个Grid,在该Grid上有一个Tabcontrol。 这篇文章看来,一些控件似乎没有调整大小。 那么这是否意味着TabControl即使在Grid上也无法调整大小?

当用户调整ToolWindowPane的大小时,内容不会调整大小。 在这种情况下如何才能实现正确的大小调整?

在此输入图像描述

要使页面在分辨率/设备上可销售,您必须确保没有指定固定的宽度/高度属性; 相反,我们可以以百分比(%)使用它们,这将使控件根据可用视口进行缩放。 尝试使用百分比替换控件的所有固定高度和宽度属性。

如果由于某些原因控件被挤压,您可以尝试为控件提供minHeight和minWidth,如下所示https://www.w3schools.com/cssref/pr_dim_min-height.asp

问题的基础是显式Width和Height值被设置并阻止控件装入其容器。

暂无
暂无

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

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