123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace NEIntelligentControl2.Views.AGC
- {
-
-
-
- public partial class DotView : UserControl
- {
-
- public static readonly RoutedEvent ChangedEvent = EventManager.RegisterRoutedEvent("Changed", RoutingStrategy.Bubble, typeof(EventHandler<DotChangedRoutedEventArgs>), typeof(DotView));
- public event RoutedEventHandler Changed { add { AddHandler(ChangedEvent, value); } remove { RemoveHandler(ChangedEvent, value); } }
- private Dictionary<RadioButton, int> _ButtonPairs;
- private int count;
-
-
-
- public int Count
- {
- get => count;
- set
- {
- count = value;
- _ButtonPairs = new Dictionary<RadioButton, int>();
- _SPMain.Children.Clear();
- var style = this.Resources["MainRadioButtonStyle"] as Style;
- for (int i = 0; i < count; ++i)
- {
- RadioButton rb = new RadioButton() { Style = style };
- rb.Checked += DotChecked;
- _ButtonPairs.Add(rb, i);
- _SPMain.Children.Add(rb);
- }
- }
- }
- private void DotChecked(object sender, RoutedEventArgs e)
- {
- RadioButton rb = sender as RadioButton;
- if (rb == null) return;
- DotChangedRoutedEventArgs dcre = new DotChangedRoutedEventArgs(ChangedEvent, sender, this[rb]);
- RaiseEvent(dcre);
- }
-
-
-
-
-
- public bool Check(int index)
- {
- foreach (var v in _ButtonPairs)
- {
- if (v.Value == index)
- {
- v.Key.IsChecked = true;
- return true;
- }
- }
- return false;
- }
-
-
-
-
-
- public int this[RadioButton rb]
- {
- get
- {
- if (_ButtonPairs.ContainsKey(rb))
- return _ButtonPairs[rb];
- return -1;
- }
- }
- public DotView()
- {
- _ButtonPairs = new Dictionary<RadioButton, int>();
- InitializeComponent();
- }
- }
-
-
-
- public class DotChangedRoutedEventArgs : RoutedEventArgs
- {
-
-
-
- public int Index { get; set; }
-
-
-
- public RadioButton SelectedButton { get; set; }
- public DotChangedRoutedEventArgs(RoutedEvent routedEvent, object source, int index) : base(routedEvent, source)
- {
- Index = index;
- SelectedButton = source as RadioButton;
- }
- }
- }
|