gpt4 book ai didi

c# - WPF:无法创建类型的实例

转载 作者:行者123 更新时间:2023-11-30 18:31:15 26 4
gpt4 key购买 nike

我有这个问题,所以我在 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

编辑:这是它的样子: enter image description here

最佳答案

您想通过以下行实现什么?

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

因为您将 UserControl 用作绑定(bind),我认为这不是您想要的。尝试以下访问 UserControl

的数据上下文
<Grid DataContext="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}">

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com