为columnSpan制作转换器

时间:2012-07-27 22:45:30

标签: c# windows-phone-7 xaml

我想在userControl上动态执行columnSpan。我创建了转换器类,但它没有用。你能告诉我如何正确地做到这一点吗?感谢。

我的UserControl上的代码:

<TextBlock  x:Name="txtSumary" Grid.Row="0" Grid.Column="1" Text="{Binding summary}"           
   TextWrapping="Wrap"  Style="{StaticResource PhoneTextAccentStyle}" Grid.ColumnSpan="{Binding isSpan, Converter={StaticResource ColumSpanConverter}}"  />

它是UserControl.Resources

的参考
<local:VisibilityConverter x:Key="ColumSpanConverter"/>

有转换器类:

 public class ColumSpanConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {          
        bool isSpan = (bool)value;
        return isSpan ? 2 : 0;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}

1 个答案:

答案 0 :(得分:1)

转换器引用了错误的转换器:

<local:VisibilityConverter x:Key="ColumSpanConverter"/>

应该是:

<local:ColumSpanConverter x:Key="ColumSpanConverter" />