我有一个 AdvanceBasicEffect 类,它有一个属性 SpecularColor,它是 AdvanceVector3 类的对象,所以当我绑定 specularColor.X 属性时,属性更改事件会触发,但仅在 AdvanceVector3 类中,而不在 AdvanceBasicEffect 中。
查看您将弄清楚的代码:
public partial class Lights : UserControl
{
public Lights()
{
InitializeComponent();
this.DataContext = this;
basicEffect = new AdvanceBasicEffect();
}
public AdvanceBasicEffect basicEffect { get; set; }
}
public class AdvanceBasicEffect : INotifyPropertyChanged
{
public AdvanceBasicEffect()
{
SpecularColor = new AdvanceVector3();
basicEffect = ((bathroom)CurrentWindowHandle.currentGame.Components.First()).basicEffect;
}
BasicEffect basicEffect;
AdvanceVector3 _SpecularColor;
public AdvanceVector3 SpecularColor
{
get
{
return _SpecularColor;
}
set
{
//Line 1 : event not occuring
_SpecularColor = value;
if(basicEffect!=null)
basicEffect.DirectionalLight0.Direction = new Vector3(_SpecularColor.X, _SpecularColor.Y, _SpecularColor.Z);
valueChanged("SpecularColor");
}
}
private void valueChanged(string p)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(p));
CurrentWindowHandle.currentGame.models[0].SetMeshEffect("Archinteriors7_10_80", basicEffect, false);
CurrentWindowHandle.currentGame.models[0].SetMeshEffect("Archinteriors7_10_111", basicEffect, false);
CurrentWindowHandle.currentGame.models[0].SetMeshEffect("Archinteriors7_10_112", basicEffect, false);
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
public class AdvanceVector3 : INotifyPropertyChanged
{
float _X;
public float X
{
get
{
return _X;
}
set
{
_X = value;
valueChanged("X");
}
}
float _Y;
public float Y
{
get
{
return _Y;
}
set
{
_Y = value;
valueChanged("Y");
}
}
float _Z;
public float Z
{
get
{
return _Z;
}
set
{
_Z = value;
valueChanged("Z");
}
}
private void valueChanged(string p)
{
//line 2 :Event Occuring
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(p));
//CurrentWindowHandle.currentGame.models[0].SetMeshEffect("Archinteriors7_10_80", basicEffect, false);
//CurrentWindowHandle.currentGame.models[0].SetMeshEffect("Archinteriors7_10_111", basicEffect, false);
//CurrentWindowHandle.currentGame.models[0].SetMeshEffect("Archinteriors7_10_112", basicEffect, false);
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
在评论“第 1 行”事件发生,而在“第 2 行”事件发生,所以我的问题是当子属性发生变化时,为什么父属性没有发生变化。我不能在同一个类中定义 X、Y、Z,因为我有许多需要 AdvanceVector3 类的属性
绑定代码如下:
<Slider ToolTip="SpecularColorX" Minimum="-1" Maximum="1" Value="{Binding basicEffect.SpecularColor.X}" />
<Slider ToolTip="SpecularColorY" Minimum="-1" Maximum="1" Value="{Binding basicEffect.SpecularColor.Y}" />
<Slider ToolTip="SpecularColorZ" Minimum="-1" Maximum="1" Value="{Binding basicEffect.SpecularColor.Z}" />