我想动态地在 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();
}
}