转换器绑定错误
本文关键字:错误 绑定 转换器 | 更新日期: 2023-09-27 18:15:05
我在我的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"/>
当我用背景图像动态创建新的选项卡时,我希望该图像填充mdiccontainer的高度和宽度。为此,我为图像的高度和宽度设置了made binding。
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高度,我需要没有头高度的MdiContainer 的高度。
所以我在不同的类中创建了转换器: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};
我得到错误类名在此时无效。我怎么解它?
我发现了错误var height = new Binding("ActualHeight") { Source = MdiContainer, IsAsync = true, Converter = new ImageSizeConvertor() };