问题描述
我正在尝试在 Viewport3D 中绑定 ModelVisual3D。这是一个 HelixViewport,但我认为这不是我的问题。
<DataTemplate>
<StackPanel Orientation="Vertical">
<h:HelixViewport3D ShowViewCube="False" MinHeight="80"
ZoomExtentsWhenLoaded="True">
<ModelVisual3D
Content="{Binding CargoVisual,Converter={StaticResource VisualModel3DConverter}}" />
<h:SunLight />
</h:HelixViewport3D>
<Label Content="{Binding Tag}" Foreground="{DynamicResource Foreground}"
HorizontalAlignment="Center" />
</StackPanel>
</DataTemplate>
我的 Juliet.CargoVisual 是 ModelVisual3D,但我遇到了绑定错误
无法从类型 'Juliet.CargoVisual' 转换为 'System.Windows.Media.Media3D.Model3D'。考虑设置转换器 在绑定上。
这里是说转换器:
public class VisualModel3DConverter : IValueConverter
{
public object Convert(object value,Type targettype,object parameter,CultureInfo culture)
{
if (value is ModelVisual3D modelVisual3D)
{
// for testing purposes,returning a new BoxVisual3D
return new BoxVisual3D
{
Center = new Point3D(),Length = 1
};
}
else
{
return null;
}
}
public object ConvertBack(object value,CultureInfo culture)
{
return null;
}
}
我没有留下任何错误,但视口没有显示任何内容。如果我添加另一个模型,没有绑定,它工作得很好。 我一定是做错了什么。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)