Esempio n. 1
0
        public UserControl2()
        {
            InitializeComponent();


            //MyValueとTextBoxのTextとのBinding
            var mb = new MultiBinding();

            mb.Converter = new MyStringConverter();
            //
            //mb.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;


            Binding b;

            //Value用のBinding
            b        = new Binding();
            b.Source = this;
            b.Path   = new PropertyPath(MyValueProperty);
            b.Mode   = BindingMode.TwoWay;
            mb.Bindings.Add(b);

            //StringFormat用のBinding
            b        = new Binding();
            b.Source = this;
            b.Path   = new PropertyPath(MyStringFormatProperty);
            b.Mode   = BindingMode.OneWay;//重要、TextBoxの値からはStringFormatを変換しないので渡さない
            //b.Mode = BindingMode.TwoWay;
            mb.Bindings.Add(b);


            MyTextBox.SetBinding(TextBox.TextProperty, mb);
        }
Esempio n. 2
0
        //XAMLのほうでも設定しているけど、それを上書きする
        //違うところは1箇所だけで、ConverterParameterに自身を渡しているところ
        //これはTextBoxに数値以外が入力されたときに使う
        private void SetMultiBinding()
        {
            var mb = new MultiBinding();

            mb.Converter          = new MyConverterMulti();
            mb.ConverterParameter = this;//ここをXAMLでの書き方が分かれば、このメソッドは必要ない

            var b = new Binding();

            b.Source = this;
            b.Path   = new PropertyPath(MyValueProperty);
            b.Mode   = BindingMode.TwoWay;
            mb.Bindings.Add(b);

            b        = new Binding();
            b.Source = this;
            b.Path   = new PropertyPath(MyKetaIntProperty);
            b.Mode   = BindingMode.TwoWay;
            mb.Bindings.Add(b);

            b        = new Binding();
            b.Source = this;
            b.Path   = new PropertyPath(MyKetaDecimalProperty);
            b.Mode   = BindingMode.TwoWay;
            mb.Bindings.Add(b);

            MyTextBox.SetBinding(TextBox.TextProperty, mb);
        }