Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- 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 StudyWPF
- {
- public class Data
- {
- public int Value { get; set; }
- }
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- Data Data { get; set; }
- public TypeConverter converter => TypeDescriptor.GetConverter(Data.Value.GetType());
- public static readonly DependencyProperty DataPropProperty =
- DependencyProperty.Register("DataProp", typeof(string), typeof(MainWindow), new PropertyMetadata("0",(d,e)=> {
- var o = (d as MainWindow);
- o.Data.Value = (int)o.converter.ConvertFrom((string)e.NewValue);
- }));
- public MainWindow()
- {
- InitializeComponent();
- Data = new Data();
- ValueRangeSlider.TickFrequency = 1;
- ValueRangeSlider.IsSnapToTickEnabled = true;
- ValueRangeSlider.Minimum = 0;
- ValueRangeSlider.Maximum = 100;
- //Slider <-> Textbox <--> ProxyDP
- Binding T2SBinding = new Binding();
- T2SBinding.Mode = BindingMode.TwoWay;
- T2SBinding.Source = ValueRangeSlider;
- T2SBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
- T2SBinding.Path = new PropertyPath("Value");
- Input.SetBinding(TextBox.TextProperty, T2SBinding);
- Binding T2PBinding = new Binding();
- T2PBinding.Mode = BindingMode.TwoWay;
- T2PBinding.Source = ValueRangeSlider;
- T2PBinding.Path = new PropertyPath("Value");
- this.SetBinding(DataPropProperty, T2PBinding);
- DataContext = this;
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement