【发布时间】:2013-12-13 04:00:47
【问题描述】:
我有这种情况:
<TextBlock x:Name="NoMonthDataTextBlock"
Text="No data."
Margin="20,10,0,0"
Foreground="Black"
FontWeight="Bold"
FontSize="20"
Visibility="{Binding SelectedSymbolItem.NoData, Converter={StaticResource FieldVisible}}"/>
<tools:BoolToVisibilityConverter x:Key="FieldVisible" TrueValue="Visible" FalseValue="Collapsed" />
public class BoolToVisibilityConverter : BoolToValueConverter<Visibility>
{
}
public class BoolToValueConverter<T> : IValueConverter
{
public T FalseValue { get; set; }
public T TrueValue { get; set; }
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value == null)
return FalseValue;
else
return (bool)value ? TrueValue : FalseValue;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return value != null ? value.Equals(TrueValue) : false;
}
}
问题是当SelectedSymbolItem is null 字段可见时,我不希望这样。
我希望这个 textBlock 仅在 SelectedSymbolItem 不为空且数据为空时可见。 我曾考虑过使用 Multibing,但我的目标是 Windows 商店应用程序(8.0),此处不支持。 (一个条件是不为空,另一个条件是没有数据。)
当 SelectedSymbolItem 为空时,如何使 textBlock 折叠?
【问题讨论】:
-
FallbackValue="Collapsed"
标签: wpf binding windows-store-apps