2016-08-14 35 views
0

首先,這裏是我的XAML標記(ModifySpDefaultValues.xaml):不能見得到的佈局權(WPF)

<Page x:Class="EMS_WPF_Test.ModifySpDefaultValues" 
    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:EMS_WPF_Test" 
    mc:Ignorable="d" d:DesignWidth="360" Title="ModifyPvDefaultValues" Style="{DynamicResource Form}" d:DesignHeight="360" MinHeight="360" MinWidth="360"> 
<ScrollViewer Margin="10" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> 
    <DockPanel> 
     <StackPanel DockPanel.Dock="Left"> 
      <Label Content="Min/max" Style="{DynamicResource Label}"/> 
      <Label Content="Minimum allowed sp:" Style="{DynamicResource Label}"/> 
      <Label Content="Maximum allowed sp:" Style="{DynamicResource Label}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <Label Content="Alarm values" Style="{DynamicResource Label}"/> 
      <Label Content="Period:" Style="{DynamicResource Label}"/> 
      <Label Content="Min Pv:" Style="{DynamicResource Label}"/> 
      <Label Content="Max Pv:" Style="{DynamicResource Label}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <Label Content="Local setpoint" Style="{DynamicResource Label}"/> 
      <Label Content="Default setpoint:" Style="{DynamicResource Label}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <Label Content="External setpoint" Style="{DynamicResource Label}"/> 
      <Label Content="Sp addition:" Style="{DynamicResource Label}"/> 
      <Label Content="Default manual setpoint:" Style="{DynamicResource Label}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <Label x:Name="GoBack" Content="Back" Style="{DynamicResource Hyperlink}" MouseLeftButtonUp="GoBack_MouseLeftButtonUp"/> 
     </StackPanel> 
     <StackPanel DockPanel.Dock="Right"> 
      <Label Style="{DynamicResource Label}"/> 
      <Label Content="What's this?" Style="{DynamicResource Hyperlink}"/> 
      <Label Content="What's this?" Style="{DynamicResource Hyperlink}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <Label Content="What's this?" Style="{DynamicResource Hyperlink}"/> 
      <Label Content="What's this?" Style="{DynamicResource Hyperlink}"/> 
      <Label Content="What's this?" Style="{DynamicResource Hyperlink}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <Label Content="What's this?" Style="{DynamicResource Hyperlink}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <Label Content="What's this?" Style="{DynamicResource Hyperlink}"/> 
      <Label Content="What's this?" Style="{DynamicResource Hyperlink}"/> 
     </StackPanel> 
     <StackPanel> 
      <Label Style="{DynamicResource Label}"/> 
      <TextBox Style="{DynamicResource TextBox}"/> 
      <TextBox Style="{DynamicResource TextBox}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <TextBox Style="{DynamicResource TextBox}"/> 
      <TextBox Style="{DynamicResource TextBox}"/> 
      <TextBox Style="{DynamicResource TextBox}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <TextBox Style="{DynamicResource TextBox}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <Label Style="{DynamicResource Label}"/> 
      <TextBox Style="{DynamicResource TextBox}"/> 
      <TextBox Style="{DynamicResource TextBox}"/> 
     </StackPanel> 
    </DockPanel> 
</ScrollViewer> 

XAML的窗口(加載網頁上面):

<NavigationWindow x:Class="EMS_WPF_Test.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:EMS_WPF_Test" 
    mc:Ignorable="d" 
    Title="Modify device" MinHeight="300" MinWidth="680" Height="300" Width="680" Source="ModifySpDefaultValues.xaml" WindowStartupLocation="CenterScreen" ShowsNavigationUI="False"> 

樣式:

<Application x:Class="Test.App" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
StartupUri="MainWindow.xaml"> 
<Application.Resources> 
    <!-- Header text style --> 
    <Style x:Key="Hyperlink"> 
     <Setter Property="Label.Margin" Value="0,0,25,0"></Setter> 
     <Setter Property="Label.Foreground" Value="{DynamicResource {x:Static SystemColors.HotTrackBrushKey}}"></Setter> 
     <Setter Property="Label.Cursor" Value="Hand"></Setter> 
     <Setter Property="Label.Height" Value="20"></Setter> 
     <Setter Property="Label.Padding" Value="0"/> 
    </Style> 
    <Style x:Key="OperationMethodBox"> 
     <Setter Property="Label.Margin" Value="0,0,25,0"></Setter> 
     <Setter Property="ComboBox.Width" Value="300"></Setter> 
     <Setter Property="Label.Height" Value="20"></Setter> 
     <Setter Property="Label.Padding" Value="0"/> 
    </Style> 
    <Style x:Key="TextBox"> 
     <Setter Property="Label.Margin" Value="0,0,25,0"></Setter> 
     <Setter Property="TextBox.MinWidth" Value="50"></Setter> 
     <Setter Property="Label.Height" Value="20"></Setter> 
     <Setter Property="Label.Padding" Value="0"/> 
    </Style> 
    <Style x:Key="Label"> 
     <Setter Property="Label.Height" Value="20"/> 
     <Setter Property="Panel.Margin" Value="0,0,25,0"/> 
     <Setter Property="Label.Padding" Value="0"/> 
    </Style> 
    <Style x:Key="Form"> 
     <Setter Property="Page.Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 
    </Style> 
</Application.Resources> 

我是新來的WPF,它可能顯示。我無法讓滾動條像我想要的那樣工作。出於某種原因,垂直滾動條從未出現,即使我的窗口高度小於上面顯示的其XAML標記頁面的最小高度。

我是新來的所有這些,所以如果任何人都可以給我一些建議,我做錯了什麼或發佈有用的鏈接到有用的資源,我會很感激。

+0

ScrollBar應該工作,再次檢查。 –

+0

好吧,它不。我運行應用程序,我嘗試調整窗口的大小,但無論滾動條如何調整,滾動條都不會出現。 – Athena

+0

然後,其他事情正在干擾。沒有足夠的信息來告訴。 –

回答

0

顯然我通過從頁面中刪除MinHeight解決了它。我仍然不明白這些屬性(MinHeight/MinWidth)的重點,因爲窗口不尊重它們,並且如果添加了滾動條,它將被完全禁用。

1

你可以使用一個網格佈局,而不是

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="Auto"/> 
     <ColumnDefinition Width="*"/> 
     <ColumnDefinition Width="Auto"/> 
    </Grid.ColumnDefinitions> 
    <StackPanel Grid.Column="0"/> 
    <StackPanel Grid.Column="1"/> 
    <StackPanel Grid.Column="2"/> 
</Grid> 

第一和第三列將佔據儘可能多的空間可以根據需要,第二個會佔用休息。

至於Scrollbars:這實際上應該可以工作,你可以爲你的Frame添加XAML嗎?

+0

我想通了,我必須交換第二和第三列的上述工作。不想使用網格,因爲在前面或中間添加行會變得很繁瑣。我在第一個窗口中使用了NavigationWindow,在第一篇文章中使用了XAML。 – Athena