本文整理汇总了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");
}
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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++;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例12: CreateDataBox
TextBox CreateDataBox()
{
var dataBox = new TextBox();
dataBox.SetBinding(TextBox.TextProperty,new Binding("CellValue"){Source=_data});
return dataBox;
}
示例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;
}
示例14: GenerateEditingElementCore
protected override FrameworkElement GenerateEditingElementCore()
{
var txt = new TextBox();
txt.SetBinding(TextBox.TextProperty, this.Binding);
return txt;
}
示例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;
}