Reputation: 541
<Grid
Height="{Binding ElementName=oldPrice, Path=Height}">
<TextBlock
VerticalAlignment="Bottom"
FontSize="{StaticResource TextStyleSmallFontSize}"
RequestedTheme="Light"
FontWeight="Bold"
Foreground="#B0B0B0"
Style="{StaticResource TitleTextBlockStyle}"
TextWrapping="NoWrap">
<Run
x:Name="oldPrice"
Text="{Binding oldPrice}" />
</TextBlock>
<Line
Stretch="Fill"
Stroke="#B0B0B0"
StrokeThickness="1"
X1="1"
Width="{Binding ElementName=oldPrice, Path=Width}"
Height="{Binding ElementName=oldPrice, Path=Height}"
Margin="0,6,0,0" />
</Grid>
<TextBlock
Text="   "
FontSize="{StaticResource TextStyleMediumFontSize}"
RequestedTheme="Light"
Style="{StaticResource TitleTextBlockStyle}"
TextWrapping="NoWrap" />
Hi all, i have a textblock and a line above it for oldPrice indication. And another textblock for spacing between next text. However when there is no dicount so no oldPrice value i am setting the oldPrice text to null.
So i want to hide that spacing textblock too. Is there any possible xaml way to bind the last TextBlock's visibility property to oldPrice's text. So it will be invisible if oldPrice text is null or empty string.
Thanks
Upvotes: 3
Views: 2386
Reputation: 495
Using Converters You can achieve this
In xaml
<TextBlock x:Name="TB" Text="Text"/>
<TextBox Visibility="{Binding ElementName=TB,Path=Text,Converter={StaticResource StringToVisibilityConverter}}"/>
And Corresponding converter in c# code is
public class StringToVisibilityConverter: IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return string.IsNullOrEmpty((string)value)?Visibility.Collapsed:Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (Visibility)value == Visibility.Visible;
}
#endregion
}
If you Bind Visibility to text directly means,It will Show the text something Like Visible/Hidden always.
Upvotes: 4