private void Notifier(object sender, PropertyChangedEventArgs e) { string propName = e.PropertyName; string deviceId = string.Empty; var parts = e.PropertyName.Split('.'); if (parts.Count() > 1) { propName = parts[1]; deviceId = parts[0]; if (propName == "StandBy") { deviceId = string.Empty; } } else if (propName == CURRENT) { deviceId = CurrentDevice.UDN; } var properties = this.GetType().GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.DeclaredOnly); foreach (var prop in properties) { // Using reflection. System.Attribute[] attrs = Attribute.GetCustomAttributes(prop); // Reflection. var depAttrs = from attr in attrs where attr is DeviceAttribute select attr as DeviceAttribute; foreach (var depAttr in depAttrs) { if ((depAttr.Device == ALL) || ((depAttr.Device == CURRENT) && (CurrentDevice.UDN == deviceId)) || (string.Empty == deviceId)) { var setter = from method in GetType().GetRuntimeMethods() where method.Name == "Set" + prop.Name select method; if (setter.Count() > 0) { m_dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { setter.ElementAt(0).Invoke(this, new object[] { }); }); } } } } TuneInViewModel.Notifier(sender, e); OthersViewModel.Notifier(sender, e); PresetSelectionViewModel.NotifierAsync(sender, e); DeviceSelectionViewModel.Notifier(sender, e); }
public RunningPageViewModel() { TuneInViewModel = new TuneInViewModel(); OthersViewModel = new OthersViewModel(); PresetSelectionViewModel = new PresetSelectionViewModel(); DeviceSelectionViewModel = new DeviceSelectionViewModel(); m_dispatcherTimer = new DispatcherTimer(); m_dispatcherTimer.Tick += new EventHandler <object>((o, e) => { m_dispatcherTimer.Stop(); m_model.Screen.Dimming(true); }); }