2016-09-05 86 views
0

我有一個簡單的對話框 - A Grid與4 TextBlock的其中我綁定了第二個和第三個TextBlock的屬性的可見性,但它不像預期的那樣工作,即,條件消息在查看對話框時顯示爲截斷。該對話框的2種變體是如下:網格 - 隱藏的行和文本塊顯示問題

某些文本

條件消息1

BC

某些文本

條件消息2

B C

該對話框的XAML如下所示。

<Window 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:cl="http://www.caliburnproject.org" 
      xmlns:local="clr-namespace:ABC.DrillDown" 
      xmlns:iwpf="clr-namespace:ABC.Mvvm.Wpf;assembly=ABC.Mvvm.Wpf" 
      xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="ABC.DrillDown.Views.MessageView" 
      Title="{Binding WindowTitle}" WindowStartupLocation="CenterScreen" MaxWidth="525" MinWidth="525" Background="White" MinHeight="275" MaxHeight="275"> 
    <Window.Resources> 
      <iwpf:BoolToVisibilityConverter x:Key="booleanToVisibilityConverter"/> 
     </Window.Resources> 
     <Grid Margin="0,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="514" > 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto" MinHeight="64"/> 
       <RowDefinition Height="{Binding TransactionsModified, Converter={StaticResource booleanToVisibilityConverter}}"> 
        <RowDefinition.Style> 
         <Style TargetType="{x:Type RowDefinition}"> 
          <Setter Property="Height" Value="Auto" /> 
          <Style.Triggers> 
<!--Hide Row-1--> 
           <DataTrigger Binding="{Binding TransactionsModified}" Value="False"> 
            <Setter Property="Height" Value="0" /> 
           </DataTrigger> 
          </Style.Triggers> 
         </Style> 
        </RowDefinition.Style> 
       </RowDefinition> 
       <RowDefinition Height="{Binding TransactionsDeleted, Converter={StaticResource booleanToVisibilityConverter}}"> 
        <RowDefinition.Style> 
         <Style TargetType="{x:Type RowDefinition}"> 
          <Setter Property="Height" Value="Auto" /> 
          <Style.Triggers> 
<!--Hide Row-2--> 
           <DataTrigger Binding="{Binding TransactionsDeleted}" Value="false"> 
            <Setter Property="Height" Value="0" /> 
           </DataTrigger> 
          </Style.Triggers> 
         </Style> 
        </RowDefinition.Style> 
       </RowDefinition> 
       <RowDefinition Height="Auto" MinHeight="80"/> 
       <RowDefinition Height="Auto" MinHeight="30"/> 
       <RowDefinition Height="Auto" MinHeight="12"/> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="Auto"/> 
      </Grid.ColumnDefinitions> 
      <TextBlock Grid.Row="0" Grid.Column="0" TextWrapping="NoWrap" HorizontalAlignment="Left" xml:space="preserve" VerticalAlignment="Top" Height="64" Width="478">Some Text   </TextBlock> 
       <TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding TransactionsModified}" Visibility="{Binding TransactionsModified, Converter={StaticResource booleanToVisibilityConverter}}" TextWrapping="NoWrap" HorizontalAlignment="Left" xml:space="preserve" Width="0" > 
       Conditional Text - 1 
      </TextBlock> 

      <TextBlock Grid.Row="2" Grid.Column="0" Text="{Binding TransactionsDeleted}" Visibility="{Binding TransactionsDeleted, Converter={StaticResource booleanToVisibilityConverter}}" TextWrapping="NoWrap" HorizontalAlignment="Left" xml:space="preserve" Width="0"> 
       Conditional Text - 2 
      </TextBlock> 
      <TextBlock Grid.Row="3" Grid.Column="0" TextWrapping="NoWrap" HorizontalAlignment="Left" xml:space="preserve" Width="425"> 
       Text 3 

       Text 4 
      </TextBlock> 
      </Grid> 
      </Window> 

C 

回答

1

你有幾個RowDefinition的地方有一個錯誤的高度(你應該刪除這部分)

Height="{Binding TransactionsModified, Converter={StaticResource booleanToVisibilityConverter}}"> 

當然直接結合高度爲BOOL中是沒有意義的:你已經有了更多在以下部分合理觸發(他們一見鍾情)