【问题标题】:WPF: Could not create a instance of typeWPF:无法创建类型的实例
【发布时间】:2013-12-10 23:32:03
【问题描述】:

我有这个问题,所以在 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.dllVolumeControlInterface中的引用都会显示一个警告,说找不到vtkVolumeControl.dll;但是如果我继续构建VolumeControlInterface,它不会有任何问题,而且它似乎设法找到vtkVolumeControl.dll

编辑: 这是它的外观:

【问题讨论】:

标签: c# wpf


【解决方案1】:

你想用下面这行实现什么?

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

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

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

【讨论】:

  • 谢谢,但它似乎给出了同样的错误。仍然无法创建 VolumeRender。 xaml 不显示。
  • 你能用堆栈发布完整的异常并寻找内部异常吗?
  • 当然可以,但是在哪里可以找到完整的异常?
猜你喜欢
  • 2010-10-26
  • 2018-05-25
  • 2020-02-02
  • 2021-11-15
  • 2021-10-01
  • 1970-01-01
  • 2016-10-04
  • 2021-10-24
  • 2020-05-10
相关资源
最近更新 更多