我试图消除所有我的运行时绑定错误,以加快我的应用程序,但我有一些错误,给我麻烦,我无法解决。 我的主要问题在于显示3D内容的用户控件。 我告诉他们在一段代码:在执行时间绑定错误
<Viewport3D xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="viewport" ClipToBounds="False" IsHitTestVisible="False">
<Viewport3D.Camera>
<PerspectiveCamera FieldOfView="45" NearPlaneDistance="0.125" FarPlaneDistance="Infinity" Position="-176.298724337988,214.871512878159,289.862943629443" LookDirection="0.469846310392954,-0.342020143325669,-0.813797681349374" UpDirection="0.171010071662834,0.939692620785908,-0.296198132726024"/>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<Model3DGroup.Transform>
<Transform3DGroup>
<ScaleTransform3D ScaleZ="{Binding CurrentScale}" ScaleY="1" ScaleX="1"/>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="0,-1,0" Angle="{Binding CurrentAngle}"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<MatrixTransform3D Matrix="1,1,-1,0,1,1,-3,0,0,-1,3,0,0,48,32,1"/>
</Transform3DGroup>
</Model3DGroup.Transform>
<GeometryModel3D x:Name="Box02">
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="1 1 1 "/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial Brush="{Binding CurrentColor}"/>
</GeometryModel3D.Material>
</GeometryModel3D>
<Model3DGroup>
<DirectionalLight Direction="{Binding CurrentLight}" Color="#FFFFFF" x:Name="light"/>
</Model3DGroup>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
我的绑定有以下几种,我已经得到了在MSDN的类型(连在绑定) https://msdn.microsoft.com/en-us/library/system.windows.media.media3d.directionallight.direction(v=vs.110).aspx 类型:System.Windows.Media.Media3D。的Vector3D
public System.Windows.Media.Media3D.Vector3D CurrentLight
{
get { return this.currentLight; }
set
{
this.currentLight = value;
this.OnPropertyChanged("CurrentLight");
}
}
protected System.Windows.Media.Media3D.Vector3D currentLight;
https://msdn.microsoft.com/en-us/library/system.windows.media.media3d.scaletransform3d.scalez(v=vs.110).aspx 类型:System.Double
public double CurrentScale
{
get { return this.currentScale; }
set
{
this.currentScale = value;
this.OnPropertyChanged("CurrentScale");
}
}
protected double currentScale;
https://msdn.microsoft.com/en-us/library/system.windows.media.media3d.axisanglerotation3d.angle(v=vs.110).aspx 类型:System.Double
public double CurrentAngle
{
get { return this.currentAngle; }
set
{
this.currentAngle = value;
this.OnPropertyChanged("CurrentAngle");
}
}
protected double currentAngle;
https://msdn.microsoft.com/en-us/library/system.windows.media.media3d.diffusematerial.brush(v=vs.110).aspx 类型:System.Windows.Media.Brush
public System.Windows.Media.Brush CurrentColor
{
get { return this.currentColor; }
set
{
this.currentColor = value;
this.OnPropertyChanged("CurrentColor");
}
}
protected System.Windows.Media.Brush currentColor;
虽然绑定正常工作,出现以下消息在运行时:
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=CurrentScale; DataItem=null; target element is 'ScaleTransform3D' (HashCode=27183531); target property is 'ScaleZ' (type 'Double')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=CurrentAngle; DataItem=null; target element is 'AxisAngleRotation3D' (HashCode=2594575); target property is 'Angle' (type 'Double')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=CurrentColor; DataItem=null; target element is 'DiffuseMaterial' (HashCode=7565331); target property is 'Brush' (type 'Brush')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=CurrentLight; DataItem=null; target element is 'DirectionalLight' (HashCode=4095240); target property is 'Direction' (type 'Vector3D')
在Stackoverflow中搜索后,我找到了一个关于使用“回退值”的解决方案?这是最好的解决方案吗? Getting many Binding "Information" in WPF output window)
我在另一个线程堆栈溢出看到他们建议使用下面的语句(How to eliminate Binding “Information” in WPF output window - cannot retrieve value using the binding):
System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level = System.Diagnostics.SourceLevels.Critical;
无论如何,为什么会出现这些错误?我知道我使用的类型是正确的,因为我已经在MSDN提供的链接中检查过它们,它是正确的吗?
谢谢
请改善您的答案,以便OP了解为什么您提供的解决方案将有所帮助。此外,在您发布的链接中,尝试检索相关部分,以备份您的答案。 – aribeiro
正如我在其他答案中所述,将DataContext分配给viewmodel不会在执行时间中删除绑定错误。 –