| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using MuchInfo.Chart.Infrastructure.Utilities;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- using System.Windows;
- using System.Windows.Controls;
- namespace MuchInfo.Chart.Infrastructure.Controls
- {
- /// <summary>
- /// BooleanEditor.xaml 的交互逻辑
- /// </summary>
- public partial class BooleanEditor : UserControl
- {
- #region Fields
- private List<ControlPair> _controlPairs;
- private string _propertyName;
- private object _target;
- #endregion Fields
- #region Constructors
- public BooleanEditor()
- {
- this.InitializeComponent();
- }
- public BooleanEditor(object target, string propertyName, string label)
- : this(RuntimeHelpers.GetObjectValue(target), propertyName, label, null)
- {
- }
- public BooleanEditor(object target, string propertyName, string label, List<ControlPair> enableTargets)
- {
- this.InitializeComponent();
- this.SetUp(RuntimeHelpers.GetObjectValue(target), propertyName, label, enableTargets);
- }
- #endregion Constructors
- #region Properties
- #region Public Properties
- //private bool BooleanEditor_1230;
- public string Label
- {
- get
- {
- return this.chkItem.Content.ToString();
- }
- set
- {
- this.chkItem.Content = (value);
- }
- }
- #endregion Public Properties
- #endregion Properties
- #region Methods
- #region Public Methods
- public void SetUp(object target, string propertyName, string label, List<ControlPair> enableTargets)
- {
- this._controlPairs = enableTargets;
- this._target = RuntimeHelpers.GetObjectValue(target);
- this._propertyName = propertyName;
- this.Initialize();
- this.chkItem.Content = label;
- }
- #endregion Public Methods
- #region Private Methods
- private void chkItem_Checked(object sender, RoutedEventArgs e)
- {
- this.SetPropertyValue(true);
- this.ShowControlPairs();
- }
- private void chkItem_Unchecked(object sender, RoutedEventArgs e)
- {
- this.SetPropertyValue(false);
- this.ShowControlPairs();
- }
- private void Initialize()
- {
- var type = this._target.GetType();
- var property = type.GetProperty(this._propertyName);
- var objectValue = RuntimeHelpers.GetObjectValue(property.GetGetMethod().Invoke(RuntimeHelpers.GetObjectValue(this._target), null));
- var flag = (bool)objectValue;
- this.chkItem.IsChecked = flag;
- this.ShowControlPairs();
- }
- private void SetPropertyValue(bool aVal)
- {
- var type = this._target.GetType();
- var property = type.GetProperty(this._propertyName);
- var array = new object[]
- {
- aVal
- };
- property.GetSetMethod().Invoke(RuntimeHelpers.GetObjectValue(this._target), array);
- }
- private void ShowControlPairs()
- {
- bool flag = this._controlPairs != null;
- if (flag)
- {
- foreach (var item in _controlPairs)
- {
- var isChecked = this.chkItem.IsChecked;
- item.SetVisible(isChecked != null && isChecked.Value);
- }
- }
- }
- #endregion Private Methods
- #endregion Methods
- }
- }
|