當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。