当前位置: 首页>>代码示例>>C#>>正文


C# TextBox.SetBinding方法代码示例

本文整理汇总了C#中System.Windows.Controls.TextBox.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.SetBinding方法的具体用法?C# TextBox.SetBinding怎么用?C# TextBox.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.TextBox的用法示例。


在下文中一共展示了TextBox.SetBinding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MainWindow

 public MainWindow()
 {
     MemoryStream iconstream = new MemoryStream();
     Properties.Resources.sudokusolver.Save(iconstream);
     iconstream.Seek(0, SeekOrigin.Begin);
     this.Icon = System.Windows.Media.Imaging.BitmapFrame.Create(iconstream);
     InitializeComponent();
     DataContext = new SudokuGrid();
     foreach (var square in (DataContext as SudokuGrid).Squares)
     {
         TextBox sudokuSquare = new TextBox();
         sudokuSquare.DataContext = square;
         sudokuSquare.SetBinding(TextBox.TextProperty, new Binding("Value") { Converter = new StringToNullableIntConverter(), Mode = BindingMode.TwoWay });
         sudokuSquare.Width = 25;
         sudokuSquare.FontFamily = new System.Windows.Media.FontFamily("Tahoma");
         sudokuSquare.FontSize = 14;
         sudokuGrid.Children.Add(sudokuSquare);
         sudokuSquare.SetValue(Grid.RowProperty, square.Row);
         sudokuSquare.SetValue(Grid.ColumnProperty, square.Column);
         double bottomThickness = (square.Row == 2 || square.Row == 5) ? 2 : 0;
         double rightThickness = (square.Column == 2 || square.Column == 5) ? 2 : 0;
         sudokuSquare.Margin = new Thickness(0, 0, rightThickness, bottomThickness);
         sudokuSquare.SetBinding(TextBox.ToolTipProperty, "PossibleValuesString");
     }
 }
开发者ID:Mellen,项目名称:SudokuSolver,代码行数:25,代码来源:MainWindow.xaml.cs

示例2: find_all_bindings

 public void find_all_bindings()
 {
     var dataContext = new Data();
     var tb = new TextBox { DataContext = dataContext };
     tb.SetBinding(UIElement.VisibilityProperty, "IsVisible");
     tb.SetBinding(TextBox.TextProperty, "Text");
     var bndg = tb.GetBindings();
     bndg.Should().HaveCount(2);
 }
开发者ID:flq,项目名称:XamlTags,代码行数:9,代码来源:BindingIdentificationTests.cs

示例3: Clock

        public Clock(Gates.IOGates.Clock gate)
            : base(gate, new TerminalID[] { new TerminalID(false, 0, Position.TOP) })
        {

            _clock = gate;



            Rectangle r = new Rectangle();
            r.Margin = new System.Windows.Thickness(5, 17, 5, 17);
            r.Width = this.Width - 10;
            r.Height = this.Height - 34;
            r.Stroke = Brushes.Black;
            r.StrokeThickness = 2;
            r.Fill = Brushes.White;
            myCanvas.Children.Add(r);

            Path ph = new Path();
            ph.Data = StreamGeometry.Parse("M 10,22 h 5 v 5 h -5 v 5 h 5 v 5 h -5 v 5 h 5");
            ph.Stroke = Brushes.Black;
            ph.StrokeThickness = 2;
            ph.Fill = Brushes.White;
            myCanvas.Children.Add(ph);

            nval = new TextBox();
            nval.Margin = new System.Windows.Thickness(20, 23, 10, 23);
            nval.FontFamily = new FontFamily("Courier New");
            nval.FontSize = 12;
            nval.TextAlignment = TextAlignment.Center;
            nval.Width = 34;
            nval.Height = 18;
            nval.Background = Brushes.AntiqueWhite;


            Binding bind = new Binding("Milliseconds");
            bind.Source = _clock;
            bind.FallbackValue = "0";
            bind.Mode = BindingMode.TwoWay;
            bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            bind.ValidatesOnExceptions = true;
            nval.SetBinding(TextBox.TextProperty, bind);


            Binding bindve = new Binding("(Validation.Errors)[0].Exception.InnerException.Message");
            bindve.Source = nval;
            bindve.Mode = BindingMode.OneWay;
            bindve.FallbackValue = "Clock period in milliseconds";
            nval.SetBinding(TextBox.ToolTipProperty, bindve);


            myCanvas.Children.Add(nval);


        }
开发者ID:buptkang,项目名称:LogicPad,代码行数:54,代码来源:Clock.cs

示例4: Bind_Poco_TwoWay

        static void Bind_Poco_TwoWay()
        {
            // Binding Source (Any object).
            var person = new Person0 { Id = 123, Name = "Taro" };

            // Binding Target (DependencyObject).
            var textBox = new TextBox { Text = "Default" };
            Console.WriteLine(textBox.Text);

            // Binds target to source.
            var binding = new Binding(nameof(person.Name)) { Source = person, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged };
            textBox.SetBinding(TextBox.TextProperty, binding);
            Console.WriteLine(textBox.Text);

            // Changes source value.
            // Notification does not work in usual property setting.
            //person.Name = "Jiro";
            var properties = TypeDescriptor.GetProperties(person);
            properties[nameof(person.Name)].SetValue(person, "Jiro");
            Console.WriteLine(textBox.Text);

            // Changes target value.
            textBox.Text = "Saburo";
            Console.WriteLine(person.Name);
        }
开发者ID:sakapon,项目名称:Samples-2016,代码行数:25,代码来源:Program.cs

示例5: build_widgets

        private void build_widgets()
        {
            this.DataContext = this.target;

            TextBlock label = new TextBlock();
            label.Foreground = Brushes.White;
            label.Width = this.tblock_width;
            if (this.target == null)
            {
                label.Text = "";
            }
            else
            {
                label.Text = this.target.name;
            }

            TextBox tb = new TextBox();
            tb.Foreground = Brushes.White;
            tb.CaretBrush = Brushes.White;
            tb.Width = this.tbox_width;
            Binding binder = new Binding("Value");
            binder.Source = this.target;
            tb.SetBinding(TextBox.TextProperty, binder);

            StackPanel sp = new StackPanel();
            sp.Margin = new Thickness(2);
            sp.Orientation = Orientation.Horizontal;
            sp.Children.Add(label);
            sp.Children.Add(tb);

            this.Content = sp;
        }
开发者ID:mario007,项目名称:renmas,代码行数:32,代码来源:FloatEditor.xaml.cs

示例6: AssembleFields

        private void AssembleFields()
        {
            var rowIndex = 1;

            foreach (var prop in _editVm.Properties)
            {
                var margin = new Thickness(5);

                //Create a label for each property
                var propLabel = new Label { Content = $"{prop.Name}: ", Margin = margin };
                Grid.SetRow(propLabel, rowIndex);
                Grid.SetColumn(propLabel, 0);

                //create a textbox for each property
                //load existing data into the textbox
                var valueBinding = new Binding("Value") {Mode = BindingMode.TwoWay};
                var propValue = new TextBox
                {
                    Width = 150,
                    Margin = margin,
                    DataContext = prop
                };
                propValue.SetBinding(TextBox.TextProperty, valueBinding);
                Grid.SetRow(propValue, rowIndex);
                Grid.SetColumn(propValue, 1);

                MainControlGrid.Children.Add(propLabel);
                MainControlGrid.Children.Add(propValue);
                MainControlGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
                rowIndex++;
            }
        }
开发者ID:Frannsoft,项目名称:FrannHammer,代码行数:32,代码来源:EditorControl.xaml.cs

示例7: build_widgets

        private void build_widgets()
        {
            this.DataContext = this.target;

            TextBlock label = new TextBlock();
            if (this.target == null)
            {
                label.Text = "";
            }
            else
            {
                label.Text = this.target.name;
            }

            TextBox tb = new TextBox();
            Binding binder = new Binding("Value");
            binder.Source = this.target;
            tb.SetBinding(TextBox.TextProperty, binder);

            StackPanel sp = new StackPanel();
            sp.Orientation = Orientation.Horizontal;
            sp.Children.Add(label);
            sp.Children.Add(tb);

            this.Content = sp;
        }
开发者ID:mario007,项目名称:renmas,代码行数:26,代码来源:IntEditor.xaml.cs

示例8: HtmlEditor

        public HtmlEditor(WorkFrame frame)
            : base(frame)
        {
            Panel = new TabControl();
            Panel.Height = 640;

            TabItem editTab = new TabItem();
            editTab.Header = "编辑";
            TextBox textBox = new TextBox();
            textBox.DataContext = this;
            var binding = new Binding("Value");
            binding.Mode = BindingMode.TwoWay;
            textBox.SetBinding(TextBox.TextProperty, binding);
            editTab.Content = textBox;

            TabItem viewTab = new TabItem();
            viewTab.Header = "预览";
            Browser = new WebBrowser();
            viewTab.Content = Browser;

            Panel.Items.Add(editTab);
            Panel.Items.Add(viewTab);

            Panel.SelectionChanged += panel_SelectionChanged;

            Content = Panel;
        }
开发者ID:liny4cn,项目名称:ComBoost,代码行数:27,代码来源:HtmlEditor.cs

示例9: DateTimeEditor

        public DateTimeEditor(WorkFrame frame)
            : base(frame)
        {
            StackPanel panel = new StackPanel();
            panel.Orientation = Orientation.Horizontal;
                        
            time = new TextBox();
            time.DataContext = this;
            time.Width = 64;
            var timeBinding = new Binding("Value");
            timeBinding.Mode = BindingMode.TwoWay;
            timeBinding.Converter = this;
            time.SetBinding(TextBox.TextProperty, timeBinding);
            
            date = new DatePicker();
            date.DataContext = this;
            var dateBinding = new Binding("Value");
            dateBinding.Converter = new DateConvert(time);
            dateBinding.Mode = BindingMode.TwoWay;
            date.SetBinding(DatePicker.SelectedDateProperty, dateBinding);

            Button now = new Button();
            now.Content = "当前时间";
            now.Click += (s, e) => Value = DateTime.Now;
            
            panel.Children.Add(date);
            panel.Children.Add(time);
            panel.Children.Add(now);

            Content = panel;
        }
开发者ID:liny4cn,项目名称:ComBoost,代码行数:31,代码来源:DateTimeEditor.cs

示例10: AddBinding

 void AddBinding(TextBox box, ILocalizable source, string propertyName)
 {
     Binding binding = new Binding(propertyName);
     binding.Source = source;
     binding.Mode = BindingMode.TwoWay;
     box.SetBinding(TextBox.TextProperty, binding);
 }
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:7,代码来源:LocalizationControl.xaml.cs

示例11: OnApplyTemplate

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            TextBox = (TextBox)GetTemplateChild("PART_TextBox");
            TextBox.SetBinding(TextBox.TextProperty, new Binding { Source = this, Path = new PropertyPath(CurrentValueProperty), Mode = BindingMode.OneWay });
            TextBox.TextChanged += TextBox_TextChanged;
        }
开发者ID:alexyjian,项目名称:ComBoost,代码行数:8,代码来源:CurrencyEditor.cs

示例12: CreateDataBox

        TextBox CreateDataBox()
        {
            var dataBox = new TextBox();

            dataBox.SetBinding(TextBox.TextProperty,new Binding("CellValue"){Source=_data});

            return dataBox;
        }
开发者ID:Zeeger,项目名称:sqlassist,代码行数:8,代码来源:DataCellViewer.cs

示例13: CreateView

 public FrameworkElement CreateView(PropertyInfo property)
 {
     var inputControl = new TextBox();
     var binding = new Binding(property.Name);
     binding.Mode = BindingMode.TwoWay;
     inputControl.SetBinding(TextBox.TextProperty, binding);
     return inputControl;
 }
开发者ID:zealoussnow,项目名称:OneCode,代码行数:8,代码来源:StringConfigControl.cs

示例14: GenerateEditingElementCore

        protected override FrameworkElement GenerateEditingElementCore()
        {
            var txt = new TextBox();

            txt.SetBinding(TextBox.TextProperty, this.Binding);

            return txt;
        }
开发者ID:569550384,项目名称:Rafy,代码行数:8,代码来源:TextTreeGridColumn.cs

示例15: GenerateEditingElement

        protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
        {
            TextBox editElement = new TextBox {BorderThickness = new Thickness(0.0), Padding = new Thickness(0.0)};

            System.Windows.Data.Binding textBinding = new System.Windows.Data.Binding(cell.Column.Header + ".DisplayValue")
                                                          {Source = dataItem};
            editElement.SetBinding(TextBox.TextProperty, textBinding);

            System.Windows.Data.Binding backgroundBinding = new System.Windows.Data.Binding(cell.Column.Header + ".Background")
                                                                {Source = dataItem};
            editElement.SetBinding(TextBlock.BackgroundProperty, backgroundBinding);

            System.Windows.Data.Binding foreGroundBinding = new System.Windows.Data.Binding(cell.Column.Header + ".Foreground")
                                                                {Source = dataItem};
            editElement.SetBinding(TextBlock.ForegroundProperty, foreGroundBinding);

            return editElement;
        }
开发者ID:nagyist,项目名称:wpfrealtime,代码行数:18,代码来源:WpfGridColumn.cs


注:本文中的System.Windows.Controls.TextBox.SetBinding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。