WPF:无法创建类型的实例

时间:2013-12-09 17:30:58

标签: c# wpf

我有这个问题,所以在WPF设计期间我什么都看不见。

这是乞讨时的WPF代码:

<UserControl x:Class="VolumeControlInterface.VolumeControlInterface"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vtkVC="clr-namespace:VtkVolumeControl;assembly=VtkVolumeControl"
    xmlns:local="clr-namespace:VolumeControlInterface"
    Height="700" Width="700" Margin="5"

这是我的WPF代码在下面摆动:

<Grid DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}">
    <vtkVC:VolumeRenderer Name="VolumeControl" Width="Auto" Height="Auto" Margin="5" Grid.Column="0"
        LowerThresholdChanA="{Binding Path=BlackPoint0, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        UpperThresholdChanA="{Binding Path=WhitePoint0, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        LowerThresholdChanB="{Binding Path=BlackPoint1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        UpperThresholdChanB="{Binding Path=WhitePoint1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        LowerThresholdChanC="{Binding Path=BlackPoint2, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        UpperThresholdChanC="{Binding Path=WhitePoint2, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        LowerThresholdChanD="{Binding Path=BlackPoint3, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        UpperThresholdChanD="{Binding Path=WhitePoint3, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        IsChanASelected="{Binding Path=IsChanASelected, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
        IsChanBSelected="{Binding Path=IsChanBSelected, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
        IsChanCSelected="{Binding Path=IsChanCSelected, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
        IsChanDSelected="{Binding Path=IsChanDSelected, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
        DataSpacingZ="{Binding Path=DataSpacingZ, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        DataSpacingZMultiplier="{Binding Path=DataSpacingZMultiplier, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        FolderDirectory="{Binding Path=ZStackCacheDirectory, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
        HardwareSettingsFile="{Binding Path=HardwareSettingsFile, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
        TileIndex="{Binding Path=TileIndex, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
        WellIndex="{Binding Path=WellIndex, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
        TimePointIndex="{Binding Path=TimePointIndex, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
        TotalSystemChannels="4"
        Timepoints="1">
    </vtkVC:VolumeRenderer>
</Grid>

此项目为VolumeControlInterface,从另一个项目导入VtkVolumeControl.dll作为参考。 VolumeRendererVtkVolumeControl中的一个类。 VtkVolumeControl已成功构建,整个项目运行正常。我只是在设计VolumeControlInterface时看不到任何内容,它说&#34;无法创建类型的实例&#39; VolumeRender&#39;&#34;

我尝试过:

删除VtkVolumeControl,然后重新添加。不工作。

在构造函数中使用if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)),无法正常工作。

我想知道这里发生了什么,以及如何让设计可见?

修改: 我正在使用VS2008,WINDOWS 7 64BIT

此外,每次构建vtkVolumeControl.dll时,VolumeControlInterface中的引用都会显示警告,说无法找到vtkVolumeControl.dll;但是如果我继续构建VolumeControlInterface,那么它就不会有任何问题,而且它似乎设法找到了vtkVolumeControl.dll

修改 这是它的样子: enter image description here

1 个答案:

答案 0 :(得分:0)

您希望通过以下内容实现目标?

<Grid DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}">

因为你使用UserControl作为Binding,我认为这不是你想要的。 尝试以下操作来访问UserControl

的datacontext
<Grid DataContext="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}">