Reputation: 406
I have a simple dialog - A Grid
with 4 TextBlock
's wherein I bind the visibility of the 2nd and 3rd TextBlock
to a property but it doesn't work as expected i.e., the conditional message appears truncated when viewing the dialog. The 2 variants of the dialog are as below:
Some Text
Conditional Message 1
B C
or
Some Text
Conditional Message 2
B C
The XAML of the dialog is as attached below.
<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
Upvotes: 0
Views: 29
Reputation:
You have a couple of RowDefinition where there is a wrong Height (you should remove this part)
Height="{Binding TransactionsModified, Converter={StaticResource booleanToVisibilityConverter}}">
Of course binding Height directly to a bool makes no sense: you already have the more reasonable triggers in the following part (they look fine at first sight)
Upvotes: 1