Activity
클래스에 업데이트 할 시간임을 알리는 이벤트를 사용할 수 있습니다.
public class games
{
public event UpdatePlayerSubDelegate UpdatePlayerSub;
public delegate void UpdatePlayerSubDelegate();
private int _player;
public int player
{
get { return _player; }
set
{
_player = value;
if (_player > 2)
{
// Fire the Event that it is time to update
UpdatePlayerSub();
}
}
}
}
활동 클래스에서 이벤트를 생성자에 등록하고 필요한 업데이트를 이벤트 처리기에 쓸 수 있습니다. 10 귀하의 경우 하위에서 :
public class Activity
{
public games _Games { get; set; }
public sports _Sports { get; set; }
public Activity()
{
this._Games = new games();
this._Games.UpdatePlayerSub += _Games_UpdatePlayerSub;
this._Sports = new sports();
}
private void _Games_UpdatePlayerSub()
{
if (_Sports != null)
{
_Sports.sub = 10;
}
}
}
편집 난 그냥 태그 INotifyPropertyChanged
을 보았다. 물론이 인터페이스와 제공된 이벤트를 사용할 수도 있습니다. 다시 생성자에서 이벤트에
public class games : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private int _player;
public int player
{
get { return _player; }
set
{
_player = value;
if (_player > 2)
{
// Fire the Event that it is time to update
PropertyChanged(this, new PropertyChangedEventArgs("player"));
}
}
}
}
그리고 Activity
클래스 레지스터 : 다음과 같은 인터페이스를 구현
public Activity()
{
this._Games = new games();
this._Games.PropertyChanged += _Games_PropertyChanged;
this._Sports = new sports();
}
를 이벤트 핸들러의 몸 선언
private void _Games_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (_Sports != null)
{
_Sports.sub = 10;
}
}
을
그리고 _Sports.sub
은 자동으로 업데이트됩니다. 희망이 도움이됩니다. 물론이 업데이트를 수행하는 다른 방법이 있습니다. 그것은 내 마음에 처음 온 것입니다.
이것은 많은 다른 방법으로 잠재적으로 해결 될 수있는 사소한 문제입니다. 시도한 내용과 작동하지 않은 이유에 대한 코드를 표시해주십시오. – Ben
StackOverflow에 오신 것을 환영합니다. 답변이 도움이 되었다면 [답변 수락 방법] (http://meta.stackexchange.com/questions/5234/how-does-accepting)을 살펴보십시오. - 대답 - 직장) 게시물 –