Fix title aligment issue when subtitle is empty.

This commit is contained in:
qianlifeng
2014-02-19 23:42:21 +08:00
parent 4736921d05
commit c425313ae6
3 changed files with 30 additions and 3 deletions

View File

@@ -37,11 +37,11 @@
</Image> </Image>
<Grid Margin="5 0 5 0" Grid.Column="1"> <Grid Margin="5 0 5 0" Grid.Column="1">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition> <RowDefinition></RowDefinition>
<RowDefinition x:Name="SubTitleRowDefinition"></RowDefinition> <RowDefinition Height="Auto" x:Name="SubTitleRowDefinition"></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Style="{DynamicResource ItemTitleStyle}" VerticalAlignment="Center" x:Name="tbTitle" Text="{Binding Title}"></TextBlock> <TextBlock Style="{DynamicResource ItemTitleStyle}" VerticalAlignment="Center" x:Name="tbTitle" Text="{Binding Title}"></TextBlock>
<TextBlock Style="{DynamicResource ItemSubTitleStyle}" Grid.Row="1" x:Name="tbSubTitle" Text="{Binding SubTitle}"></TextBlock> <TextBlock Style="{DynamicResource ItemSubTitleStyle}" Visibility="{Binding SubTitle, Converter={wox:StringNullOrEmptyToVisibilityConverter}}" Grid.Row="1" x:Name="tbSubTitle" Text="{Binding SubTitle}"></TextBlock>
</Grid> </Grid>
</Grid> </Grid>
</DataTemplate> </DataTemplate>

View File

@@ -0,0 +1,26 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace Wox
{
public class StringNullOrEmptyToVisibilityConverter : MarkupExtension, IValueConverter
{
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return string.IsNullOrEmpty(value as string) ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}

View File

@@ -144,6 +144,7 @@
<Compile Include="SettingWindow.xaml.cs"> <Compile Include="SettingWindow.xaml.cs">
<DependentUpon>SettingWindow.xaml</DependentUpon> <DependentUpon>SettingWindow.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="StringNullOrEmptyToVisibilityConverter.cs" />
<Compile Include="WebSearchSetting.xaml.cs"> <Compile Include="WebSearchSetting.xaml.cs">
<DependentUpon>WebSearchSetting.xaml</DependentUpon> <DependentUpon>WebSearchSetting.xaml</DependentUpon>
</Compile> </Compile>