Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19.  
  20. namespace StudyWPF
  21. {
  22. public class Data
  23. {
  24. public int Value { get; set; }
  25. }
  26.  
  27.  
  28. /// <summary>
  29. /// MainWindow.xaml 的交互逻辑
  30. /// </summary>
  31. public partial class MainWindow : Window
  32. {
  33. Data Data { get; set; }
  34.  
  35. public TypeConverter converter => TypeDescriptor.GetConverter(Data.Value.GetType());
  36.  
  37. public static readonly DependencyProperty DataPropProperty =
  38. DependencyProperty.Register("DataProp", typeof(string), typeof(MainWindow), new PropertyMetadata("0",(d,e)=> {
  39. var o = (d as MainWindow);
  40. o.Data.Value = (int)o.converter.ConvertFrom((string)e.NewValue);
  41. }));
  42.  
  43. public MainWindow()
  44. {
  45. InitializeComponent();
  46.  
  47. Data = new Data();
  48.  
  49. ValueRangeSlider.TickFrequency = 1;
  50. ValueRangeSlider.IsSnapToTickEnabled = true;
  51.  
  52. ValueRangeSlider.Minimum = 0;
  53. ValueRangeSlider.Maximum = 100;
  54.  
  55. //Slider <-> Textbox <--> ProxyDP
  56.  
  57. Binding T2SBinding = new Binding();
  58. T2SBinding.Mode = BindingMode.TwoWay;
  59. T2SBinding.Source = ValueRangeSlider;
  60. T2SBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
  61. T2SBinding.Path = new PropertyPath("Value");
  62.  
  63. Input.SetBinding(TextBox.TextProperty, T2SBinding);
  64.  
  65. Binding T2PBinding = new Binding();
  66. T2PBinding.Mode = BindingMode.TwoWay;
  67. T2PBinding.Source = ValueRangeSlider;
  68. T2PBinding.Path = new PropertyPath("Value");
  69.  
  70. this.SetBinding(DataPropProperty, T2PBinding);
  71.  
  72. DataContext = this;
  73. }
  74.  
  75. private void Button_Click(object sender, RoutedEventArgs e)
  76. {
  77.  
  78. }
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement