2012-10-10 63 views
-1

我希望窗口根據內容大小而不是窗口大小進行滾動。目前,只有當窗口高度小於XAML中的指定高度時纔會顯示滾動條。這是XAML代碼。基於這裏的其他線程,我嘗試了各種東西,比如在網格中包裝ScrollViewer。獲取滾動窗口

<Window.Resources> 
    <src:ObservableSwitches x:Key="Switches"/> 
     <Style TargetType="{x:Type TreeViewItem}" x:Key="ModuleStyle"> 
     <Setter Property="Foreground" Value="Blue"/> 
     <Setter Property="FontSize" Value="12"/> 
    </Style> 

    <Style TargetType="{x:Type TreeViewItem}" x:Key="RedModuleStyle" BasedOn="{StaticResource ModuleStyle}"> 
     <Setter Property="Foreground" Value="Red"/> 
    </Style> 


</Window.Resources> 

<ScrollViewer IsEnabled="True" VerticalScrollBarVisibility="Visible"> 

    <Grid Margin="0,0,-211.4,-168"> 
    <StackPanel HorizontalAlignment="Stretch" Name="StackPanel1" VerticalAlignment="Stretch" Width="Auto" Margin="0,0,188.6,114"> 

     <StackPanel.Resources> 
      <Style TargetType="{x:Type Label}" x:Key="LabelStyle"> 
       <Setter Property="Foreground" Value="Blue"/> 
       <Setter Property="FontSize" Value="12"/> 
       <Setter Property="FontWeight" Value="Bold"/> 
      </Style> 
     </StackPanel.Resources> 



      <Label Content="Switch Name:" Name="Label1" Height="25" HorizontalAlignment="Left"/> 

      <Label Content="Software Version:" Name="Label2" HorizontalAlignment="Left" /> 
     <Label Content="Model Number:" Name="Label3" HorizontalAlignment="left"/> 
     <Label Content="IP Address:" Name="Label4" HorizontalAlignment="left"></Label> 
     <Label Content="Serial Number:" Name="Label5" HorizontalAlignment="Left"></Label> 
     <Label Content="Show Tech Taken:" Name="Label6" HorizontalAlignment="left"/> 

    </StackPanel> 
    <StackPanel Margin="105,0,218,489"> 
     <StackPanel.Resources> 
      <Style TargetType="{x:Type Label}" x:Key="LabelStyle"> 
       <Setter Property="FontSize" Value="12"/> 
       <Setter Property="FontWeight" Value="Bold"/> 
      </Style> 
     </StackPanel.Resources> 
     <Label Content="{Binding switchName}" Name="SwitchNameLabel" HorizontalAlignment="left" /> 
     <Label Content="{Binding swVersion}" Name="VersionLabel" HorizontalAlignment="left"/> 
     <Label Content="{Binding switchModel}" Name="ModelNumberLabel" HorizontalAlignment="Left"/> 
     <Label Content="{Binding IPAddress}" Name="IPAddressLabel" HorizontalAlignment="Left"/> 
     <Label Content="{Binding SerialNumber}" Name="SerialLabel" HorizontalAlignment="Left"/> 
     <Label Content="{Binding LastDataCaptureDate}" Name="ShowTechLabel" HorizontalAlignment="Left"/> 

    </StackPanel> 

    <StackPanel Name="ContentPanel" HorizontalAlignment="Left" Height="Auto" Margin="0,185,0,0" VerticalAlignment="Top" Width="auto" 
        ScrollViewer.VerticalScrollBarVisibility="Auto"> 
     <TreeView Name="ModulesTreeView" Height="auto" Background="GhostWhite" BorderThickness="0" Width="auto"/> 
     <TreeView Name="VSANTreeView" Height="auto" Background="GhostWhite" BorderThickness="0" Width="auto"/> 
     <TreeView Name="FCIPTreeView" MaxHeight="200" Background="GhostWhite" BorderThickness="0" Width="auto" 
        ScrollViewer.VerticalScrollBarVisibility="Auto"/> 
     <TreeView Name="IVRTreeView" Height="Auto" Background="GhostWhite" BorderThickness="0" Width="Auto" 
        ScrollViewer.VerticalScrollBarVisibility="Auto"> 

      <TreeViewItem Name="IVRTreeViewItem" Header="IVR Topology" Height="Auto" Background="GhostWhite" BorderThickness="0" Width="Auto"> 

       <TreeViewItem Name="NatEnabled" Header="NAT Enabled" Background="GhostWhite" BorderThickness="0" Width="Auto"> 
       <Label Name="NATLabel" Background="GhostWhite" BorderThickness="0" Width="Auto"></Label> 

       </TreeViewItem> 
      <TreeViewItem Name="Status" Header="Status" Background="GhostWhite" BorderThickness="0" Width="Auto"> 
       <Label Name="StatusLabel" Background="GhostWhite" BorderThickness="0" Width="Auto"></Label> 

      </TreeViewItem> 
      <TreeViewItem Name="FabricDistributionEnabled" Header="Fabric Distribution" Background="GhostWhite" BorderThickness="0" Width="Auto"> 
       <Label Name="FabricDistributionLabel" Background="GhostWhite" BorderThickness="0" Width="Auto"></Label> 

      </TreeViewItem> 
      <TreeViewItem Name="AFID" Header="AFID Listing" Background="GhostWhite" BorderThickness="0" Width="Auto"> 
       <ListView Name="AFIDListView" > 

       </ListView> 
      </TreeViewItem> 
      </TreeViewItem> 
     </TreeView> 

    </StackPanel> 
</Grid> 
</ScrollViewer> 

+0

這是wpf嗎?無法從你的xaml中分辨出來。 – mydogisbox

+0

是的,這是WPF。添加了一個標籤。抱歉。 –

+0

通過滾動你的意思有滾動條顯示或你的意思是你想要的內容有一個固定的高度,因此總有一些東西滾動? – mydogisbox

回答

3

你必須在內部電網無外網格和多個堆疊板。備份到基礎。帶有一個ScrollViewer和一個StackPanel的網格。

0

我想通了,如果我的包裹在ScrollViwer而不是網格我可以有任何我想要在網格和窗口仍然會正常滾動裏面的ScrollViewer。