简体   繁体   English

转换器绑定错误

[英]Binding error with converter

I have MdiContainer in my viewModel that I create dynamically: 我在动态创建的viewModel中有MdiContainer:

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

In Xaml I set content of this container to mdihost: 在Xaml中,我将此容器的内容设置为mdihost:

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

When I create dynamically new tab with background image, I want that image to fill height and width of the mdiContainer. 当我动态创建带有背景图像的新标签时,我希望该图像填充mdiContainer的高度和宽度。 For this purpose I made made binding for image height and width. 为此,我对图像的高度和宽度进行了绑定。

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

The problem is that height includes MdiContainer height with header height , and I need height of the MdiContainer without header height . 问题是高度包括带有标头高度的 MdiContainer高度,我需要没有标头高度的MdiContainer的高度

So I created converter in different class: 所以我创建了不同类的转换器:

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

but when Im trying to add converter to binding value : 但是当我试图将转换器添加到绑定值时:

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

I get error Class name is not valid at this point . 我收到错误, 类名此时无效 How can I solve it? 我该如何解决?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM