我遇到了这个问题,因此在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时什么都看不到,它说“无法创建'VolumeRender'类型的实例”

我试过了:

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

在构造函数中使用if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)),也不起作用。

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

编辑:
我正在使用VS2008,WINDOWS 7 64BIT

另外,每次我构建vtkVolumeControl.dll时,VolumeControlInterface中的引用都会显示警告,提示找不到vtkVolumeControl.dll。但是,无论如何继续构建VolumeControlInterface,都不会有任何问题,而且似乎可以找到vtkVolumeControl.dll

编辑:
它是这样的:

最佳答案

您想用以下代码实现什么?

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


因为您使用UserControl作为绑定,所以我认为这不是您想要的。
尝试以下操作来访问UserControl的数据上下文

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

关于c# - WPF:无法创建类型的实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20476836/

10-11 12:23