ええ、あなたは正しいです。次のようにコンバーターを作成できます。
public class StringLengthVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
var strValue = value as String;
return string.IsNullOrEmpty(strValue) ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
//We can't support this
throw new NotImplementedException();
}
}
コンバーターを使用するには、ページにリソースを追加します。
<phone:PhoneApplicationPage.Resources>
<local:StringLengthVisibilityConverter x:Key="LengthConverter" />
</phone:PhoneApplicationPage.Resources>
コンバーターlocal
の CLR 名前空間を指す xmlns に置き換えます。
その後、グリッドでコンバーターを使用できます。
<Grid Visibility="{Binding Path=m_strMail, Converter={StaticResource LengthConverter}}" />