2016-10-03 76 views
0

我为我正在开发的一个侧面项目编写了一个简单的xaml布局。当我开始将输出打印到文本框时,我的文本框的滚动条将在第一次启动我的应用程序时开始显示,但它会消失,我不知道为什么。其他答案说,我需要在我的文本框上设置一个静态高度,并使用VerticalScrollBarVisibility,所以我这样做了,但问题仍然存在。看到下面的截图,所有的帮助表示赞赏。本申请的xaml布局:滚动条在程序执行期间消失

图像1时首次推出:应用程序的 enter image description here 和图像2时输出开始打印:

enter image description here

<Window x:Class="DashboardDeployer.MainWindow" 
     x:Name="MainWindowName" 
     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:Utility="clr-namespace:DashboardDeployer.Utility" mc:Ignorable="d" Title="Dashboard Deployer" 
     DataContext="{Binding Main, Source={StaticResource Locator}}" Height="550" Width="1200" Margin="10" Icon="/DashboardDeployer;component/Blue-Monster.ico"> 

    <Window.Resources> 
    <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="Skins/MainSkin.xaml" /> 
      </ResourceDictionary.MergedDictionaries> 
     </ResourceDictionary> 
    </Window.Resources> 
    <StackPanel x:Name="TitlePanel" MaxWidth="750" 
      Margin="10" > 
    <TextBlock Text="{Binding WelcomeTitle}" 
       HorizontalAlignment="Center" 
       VerticalAlignment="Center" 
       FontSize="25" /> 
    <Grid x:Name="ContentGrid" HorizontalAlignment="Left" VerticalAlignment="Stretch" 
      FlowDirection="LeftToRight" MaxWidth="750" > 
     <Grid.RowDefinitions> 
     <RowDefinition Height="66*" /> 
     <RowDefinition Height="66*" /> 
     <RowDefinition Height="29*" /> 
     <RowDefinition Height="70*" /> 
     <RowDefinition Height="29" /> 
     <RowDefinition Height="Auto" /> 
     <RowDefinition x:Name="LastRow" Height="Auto" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="Auto" MaxWidth="750"/> 
     </Grid.ColumnDefinitions> 

     <Grid x:Name="BaseDirGrid" HorizontalAlignment="Stretch" FlowDirection="LeftToRight" Grid.Row="0" > 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto"/> 
      <ColumnDefinition Width="110"/> 
      <ColumnDefinition Width="110"/> 
     </Grid.ColumnDefinitions> 
     <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3">Dex Dashboard base directory</Label> 
     <TextBox Height="23" Grid.Row="1" MinWidth="300" HorizontalAlignment="Stretch" Margin="5" Grid.Column="0" 
       Background="{Binding LocationPath, Converter={StaticResource ValidHtmlPathBrushConverter}, UpdateSourceTrigger=Explicit}" 
       Text="{Binding LocationPath, Mode=TwoWay}" KeyUp="PathTextBox_KeyUp" 
       /> 
     <Button Grid.Row="1" Grid.Column="1" Margin="5" Height="30" Width="100" 
       Command="{Binding BrowseSourceCommand, Mode=OneWay}" >Browse</Button> 
     <Button Grid.Row="1" Grid.Column="2" Height="30" Margin="5" Width="100" 
       Command="{Binding OpenSourceCommand, Mode=OneWay}" 
       IsEnabled="{Binding LocationPath, Converter={StaticResource ValidPathBoolConverter}}" >Explorer</Button> 
     </Grid> 

     <Grid x:Name="OutputDirGrid" HorizontalAlignment="Stretch" FlowDirection="LeftToRight" Grid.Row="1" > 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto" /> 
      <ColumnDefinition Width="110"/> 
      <ColumnDefinition Width="110*"/> 
     </Grid.ColumnDefinitions> 
     <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3">Output Directory</Label> 
     <TextBox Height="23" Grid.Row="1" MinWidth="300" HorizontalAlignment="Stretch" Margin="5" Grid.Column="0" 
       Background="{Binding OutputPath, Converter={StaticResource ValidPathConverter}, UpdateSourceTrigger=Explicit}" 
       Text="{Binding OutputPath, Mode=TwoWay}" KeyUp="PathTextBox_KeyUp" 
       /> 
     <Button Grid.Row="1" Grid.Column="1" Margin="5" Height="30" Width="100" 
       Command="{Binding BrowseDestCommand, Mode=OneWay}" >Browse</Button> 
     <Button Grid.Row="1" Grid.Column="2" Height="30" Margin="5" Width="100" 
       Command="{Binding OpenDestCommand, Mode=OneWay}" 
       IsEnabled="{Binding OutputPath, Converter={StaticResource ValidPathBoolConverter}}" CommandParameter="{Binding OutputPath}">Explorer</Button> 
     </Grid> 
     <StackPanel Grid.Row="2"> 
     <DockPanel FlowDirection="LeftToRight"> 

     <Label>Change the populate document parameter: </Label> 
      <CheckBox x:Name="ChangePopulateDocument" IsChecked="{Binding Path=ChangePopulateDocument}" HorizontalAlignment="Left" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Center" /> 
     </DockPanel> 
     <DockPanel Visibility="{Binding ChangePopulateDocument, Converter={StaticResource BooleanToVisibilityConverter} }" FlowDirection="LeftToRight"> 
      <Label>Check to add (false), uncheck to remove parameter</Label> 
      <CheckBox x:Name="PopulateDocumentRequiresParameter" IsChecked="{Binding Path=PopulateDocumentRequiresParameter}" HorizontalAlignment="Left" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Center" /> 
     </DockPanel> 
     </StackPanel> 
     <Button x:Name="Deploy" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" Height="50" Margin="10" Width="150" 
       Command="{Binding PackageAndDeployCommand, Mode=OneWay}" 
       IsEnabled="{Binding SourceAndDestAreValid}" >Deploy</Button> 
     <Label Grid.Row="4" >Have you gotten latest and compiled in release mode?</Label> 
     <ProgressBar x:Name="TheProgressBar" Grid.Row="5" Height="20" Margin="20 5" IsIndeterminate="{Binding IsProcessing}" /> 
     <TextBox Name="OutputLog" Grid.Row="6" Grid.ColumnSpan="3" VerticalAlignment="Stretch" Text="{Binding ConsoleText}" 
       VerticalScrollBarVisibility="Visible" AcceptsReturn="True" TextWrapping="Wrap" 
       Height="150" /> 
    </Grid> 

    </StackPanel> 


</Window> 
+0

除非您自己裁剪底部图像,否则文本框可能会超出窗口。注意右侧边框如何丢失。请发布您的XAML代码,然后我们可以看到发生了什么。 – sondergard

回答

0

的主要原因为文本框扩大超出窗口大小,是因为这一行

<ColumnDefinition Width="Auto" MaxWidth="750"/> 

一般t他的布局是不必要的复杂。如果我认为这是通过拖拽设计师来完成的,那我会错吗?列定义为66 * 29 *等,使得控制布局非常困难,并判断它将如何看待运行时。

这是我如何构造它。它的设计是在Kaxaml,所以我不得不删除转换器和事件处理程序。

<Page 
     x:Name="MainWindowName" 
     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:Utility="clr-namespace:DashboardDeployer.Utility" mc:Ignorable="d" Title="Dashboard Deployer" 
     Margin="10"> 

    <Page.Resources> 
    </Page.Resources> 
    <Grid x:Name="TitlePanel" Margin="10" HorizontalAlignment="Stretch"> 
    <TextBlock Text="{Binding WelcomeTitle}" 
       HorizontalAlignment="Center" 
       VerticalAlignment="Center" 
       FontSize="25" /> 
    <Grid x:Name="ContentGrid" VerticalAlignment="Stretch" FlowDirection="LeftToRight" > 
     <Grid.RowDefinitions> 
     <RowDefinition Height="Auto" /> 
     <RowDefinition Height="Auto" /> 
     <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 

     <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*"/> 
      <ColumnDefinition Width="Auto"/> 
      <ColumnDefinition Width="Auto"/> 
     </Grid.ColumnDefinitions> 
     <Label Grid.Row="0" Grid.Column="0">Dex Dashboard base directory</Label> 
     <TextBox Height="23" Grid.Row="1" HorizontalAlignment="Stretch" Margin="5" Grid.Column="0" 
       Background="Green" Text="{Binding LocationPath, Mode=TwoWay}"/> 
     <Button Grid.Row="1" Grid.Column="1" Margin="5" Height="30" Width="100" 
       Command="{Binding BrowseSourceCommand, Mode=OneWay}" >Browse</Button> 
     <Button Grid.Row="1" Grid.Column="2" Height="30" Margin="5" Width="100" 
       Command="{Binding OpenSourceCommand, Mode=OneWay}" 
       IsEnabled="True" >Explorer</Button> 

     <Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3">Output Directory</Label> 
     <TextBox Height="23" Grid.Row="3" HorizontalAlignment="Stretch" Margin="5" Grid.Column="0" 
       Background="Red" 
       Text="{Binding OutputPath, Mode=TwoWay}"/> 
     <Button Grid.Row="3" Grid.Column="1" Margin="5" Height="30" Width="100" 
       Command="{Binding BrowseDestCommand, Mode=OneWay}" >Browse</Button> 
     <Button Grid.Row="3" Grid.Column="2" Height="30" Margin="5" Width="100" 
       Command="{Binding OpenDestCommand, Mode=OneWay}" 
       IsEnabled="True">Explorer</Button> 
       </Grid> 

     <StackPanel Grid.Row="1"> 
     <DockPanel FlowDirection="LeftToRight"> 
      <Label>Change the populate document parameter: </Label> 
      <CheckBox x:Name="ChangePopulateDocument" IsChecked="{Binding Path=ChangePopulateDocument}" HorizontalAlignment="Left" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Center" /> 
     </DockPanel> 
     <DockPanel Visibility="Visible" FlowDirection="LeftToRight"> 
      <Label>Check to add (false), uncheck to remove parameter</Label> 
      <CheckBox x:Name="PopulateDocumentRequiresParameter" IsChecked="{Binding Path=PopulateDocumentRequiresParameter}" HorizontalAlignment="Left" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Center" /> 
      </DockPanel> 
     </StackPanel> 

     <Grid Grid.Row="2"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 
     <Button x:Name="Deploy" Grid.Row="0" Grid.Column="0" Height="50" Margin="10" Width="150" 
       Command="{Binding PackageAndDeployCommand, Mode=OneWay}" 
       IsEnabled="{Binding SourceAndDestAreValid}" >Deploy</Button> 
     <Label Grid.Row="1" >Have you gotten latest and compiled in release mode?</Label> 
     <ProgressBar x:Name="TheProgressBar" Grid.Row="2" Height="20" Margin="20,5" IsIndeterminate="{Binding IsProcessing}" /> 
     <TextBox Name="OutputLog" Grid.Row="3" VerticalAlignment="Stretch" 
       VerticalScrollBarVisibility="Visible" AcceptsReturn="True" TextWrapping="Wrap"> 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
       The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. 
     </TextBox> 
     </Grid> 
    </Grid> 
    </Grid> 
</Page>