123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- using Microsoft.Office.Interop.Word;
- using Prism.Commands;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- 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 PDF_Master.CustomControl.CompositeControl
- {
- /// <summary>
- /// SlidComboControl.xaml 的交互逻辑
- /// </summary>
- public partial class SlidComboControl : UserControl
- {
- public List<ComboDataItem> Items { get;private set; }
- public event RoutedEventHandler ValueChanged;
- public string Title
- {
- get { return (string)GetValue(TitleProperty); }
- set {
- SetValue(TitleProperty, value); }
- }
-
- public static readonly DependencyProperty TitleProperty =
- DependencyProperty.Register("Title", typeof(string), typeof(SlidComboControl), new PropertyMetadata("Line Width"));
- //public int IndexSelected
- //{
- // get { return (int)GetValue(IndexSelectedProperty); }
- // set
- // {
- // SetValue(IndexSelectedProperty, value);
- // }
- //}
- //public static readonly DependencyProperty IndexSelectedProperty =
- // DependencyProperty.Register("IndexSelected", typeof(int), typeof(SlidComboControl), new PropertyMetadata(0));
- public string Unit
- {
- get { return (string)GetValue(UnitProperty); }
- set { SetValue(UnitProperty, value); }
- }
- public static readonly DependencyProperty UnitProperty =
- DependencyProperty.Register("Unit", typeof(string), typeof(SlidComboControl), new PropertyMetadata("pt"));
- public SlidComboControl()
- {
- InitializeComponent();
-
- Items = new List<ComboDataItem>();
- DefaultItems();
- SetLanguage();
- }
- private void SetLanguage()
- {
- //焊死了
- if(thicknessText.Text== "Line Width")
- {
- thicknessText.Text = App.MainPageLoader.GetString("Annotation_Thickness");
- }
-
- }
- public void SetItemSource(List<ComboDataItem> items)
- {
- Items = items;
- combox.ItemSource = Items;
- UpdateMaxMinValue(items);
- }
- private void UpdateMaxMinValue(List<ComboDataItem> items)
- {
- double MaxValue = 0;
- double MinValue = 0;
- if (items != null)
- {
- foreach (var item in items)
- {
- if (item.Value >= MaxValue)
- MaxValue = item.Value;
- }
- MinValue = MaxValue;
- foreach (var item in items)
- {
- if (item.Value <= MinValue)
- MinValue = item.Value;
- }
- ThicknessSlider.Maximum = MaxValue;
- ThicknessSlider.Minimum = MinValue;
- }
- }
- private void DefaultItems()
- {
- var item = new ComboDataItem(3);
- Items.Add(item);
- item = new ComboDataItem(6);
- Items.Add(item);
- item = new ComboDataItem(9);
- Items.Add(item);
- item = new ComboDataItem(12);
- Items.Add(item);
- item = new ComboDataItem(15);
- Items.Add(item);
- item = new ComboDataItem(18);
- Items.Add(item);
- item = new ComboDataItem(21);
- Items.Add(item);
- item = new ComboDataItem(24);
- Items.Add(item);
- combox.ItemSource = Items;
- UpdateMaxMinValue(Items);
- }
- private void UserControl_Loaded(object sender, RoutedEventArgs e)
- {
- //ThicknessSlider.ValueChanged += ThicknessSlider_ValueChanged;
- combox.ValueChanged -= combox_ValueChanged;
- combox.ValueChanged += combox_ValueChanged;
- }
- private void combox_ValueChanged(object sender, RoutedEventArgs e)
- {
- if (sender is double == true)
- {
- //点击下拉框时触发
- if (combox.IsExistInComBox(sender))
- {
- Trace.WriteLine("combox_ValueChanged" + (double)sender);
- ThicknessSlider.Value = (double)sender;
-
- ValueChanged?.Invoke((double)sender, null);
- }
- }
- }
- //事件重复SelectedValuePropertyChanged 2023/4/4
- //private void ThicknessSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
- //{
- // combox.SelectedItems = new ComboDataItem(Value);
- // // ValueChanged?.Invoke(Value, null);
- //}
- //暂无作用,后续准备
- public int SelectedIndex
- {
- get { return (int)GetValue(SelectedIndexProperty); }
- set { SetValue(SelectedIndexProperty, value);
- }
- }
- public static readonly DependencyProperty SelectedIndexProperty =
- DependencyProperty.Register("SelectedIndex", typeof(int), typeof(SlidComboControl), new PropertyMetadata(0));
- public double Value
- {
- get { return (double)GetValue(ValueProperty); }
- set { SetValue(ValueProperty, value); }
- }
- public static readonly DependencyProperty ValueProperty =
- DependencyProperty.Register("Value", typeof(double), typeof(SlidComboControl), new PropertyMetadata(1.0, SelectedValuePropertyChanged));
- private static void SelectedValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- var control = d as SlidComboControl;
- var value = (double)e.NewValue;
- if (control != null)
- {
-
- Trace.WriteLine("SelectedValuePropertyChanged" + value);
- control.combox.SelectedItems = new ComboDataItem(value, control.Unit);
- }
- }
- public List<ComboDataItem> ItemsSource
- {
- get { return (List<ComboDataItem>)GetValue(ItemsSourceProperty); }
- set { SetValue(ItemsSourceProperty, value); }
- }
- public static readonly DependencyProperty ItemsSourceProperty =
- DependencyProperty.Register("ItemsSource", typeof(List<ComboDataItem>), typeof(SlidComboControl), new PropertyMetadata(null, SelectedItemsSourcePropertyChanged));
- private static void SelectedItemsSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- var control = d as SlidComboControl;
- var value = (List<ComboDataItem>)e.NewValue;
- if (control != null && value != null)
- {
- control.SetItemSource(value);
- }
- }
- private void ThicknessSlider_PreviewMouseMove(object sender, MouseEventArgs e)
- {
- if(e.LeftButton == MouseButtonState.Pressed)
- {
- ValueChanged?.Invoke(ThicknessSlider.Value, null);
- }
- }
- }
- }
|