0

我想动态地在 userControl 上做 columnSpan。我创建了转换器类,但它不起作用。你能告诉我如何正确地做吗?谢谢。

我的用户控件上的代码:

<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();
    }
}
4

1 回答 1

1

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

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

应该:

<local:ColumSpanConverter x:Key="ColumSpanConverter" />
于 2012-07-27T22:56:10.027 回答