开发者

WPF window changing the value of another window's control

I am new to WPF. I have a window that opens another wi开发者_Python百科ndow. This second window would like to change the opacity of a label in the first window. How can I control this value from another window?


I think it is better to use a common class outside and Bind the Opacity to a property.

Use INotifyPropertyChanged for the class so that whenever you update the property, the bound Opacity element for the window automatically been modified.

public class Model :INotifyPropertyChanged
{
  .... Implement interface ... 

  public double Opacity
  {
    get { return this._opacity; } 
    set {this._opacity = value; this.OnPropertyChanged("Opacity"); } 
  }
}

In this way if both of your classes can access the same object of Model, and you bind Opacity of the form with the Opacity property of the Model, it will update the control using INotifyPropertyChanged.

To create an object for which all objects have access, use App.Resources.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜