首页 文章

转换器的绑定错误

提问于
浏览
0

我在我动态创建的viewModel中有MdiContainer:

public MainWindowViewModel()
    {
         MdiContainer = new TabbedMdiContainer();
    }                                          
    public TabbedMdiContainer MdiContainer { get; private set; }

在Xaml中,我将此容器的内容设置为mdihost:

<docking:TabbedMdiHost x:Uid="ALTabbedMdiHost" Grid.Row="1" IsEnabled="True" Content="{Binding MdiContainer}" IsCloseButtonOnTab="False"/>

当我使用背景图像动态创建新选项卡时,我希望该图像填充mdiContainer的高度和宽度 . 为此,我制作了图像高度和宽度的绑定 .

var height = new Binding("ActualHeight") { Source = MdiContainer, IsAsync = true};
 var width = new Binding("ActualWidth") { Source = MdiContainer ,IsAsync = true};
 _img.SetBinding(FrameworkElement.HeightProperty, height);
 _img.SetBinding(FrameworkElement.WidthProperty, width);

问题是高度包括MdiContainer高度 with header height ,我需要MdiContainer without header height 的高度 .

所以我在不同的类中创建了转换器:

public class ImageSizeConvertor : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return ((double) value - 1000);
    }

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

但是当我试图将转换器添加到绑定值时:

var height = new Binding("ActualHeight") { Source = MdiContainer, IsAsync = true, Converter = ImageSizeConvertor};

我得到错误类名在此时无效 . 我该如何解决?

1 回答

  • 0

    我发现错误) var height = new Binding("ActualHeight") { Source = MdiContainer, IsAsync = true, Converter = new ImageSizeConvertor() };

相关问题