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);

问题是 height 包括 MdiContainer height和 header height,我需要没有 header height 的 MdiContainer 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};

我得到错误Class name is not valid at this point。我该如何解决?

4

1 回答 1

0

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

于 2013-05-27T06:46:12.763 回答