本文整理汇总了C#中System.Windows.Controls.TextBox.SetCurrentValue方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.SetCurrentValue方法的具体用法?C# TextBox.SetCurrentValue怎么用?C# TextBox.SetCurrentValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.TextBox
的用法示例。
在下文中一共展示了TextBox.SetCurrentValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateSourceTest
public void UpdateSourceTest()
{
var textBox = new TextBox();
var fakeVm = new FakeVm();
var binding = new Binding("Value")
{
Source = fakeVm,
UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
NotifyOnSourceUpdated = true,
NotifyOnTargetUpdated = true,
Mode = BindingMode.TwoWay
};
BindingOperations.SetBinding(textBox, TextBox.TextProperty, binding);
textBox.DataContext = fakeVm;
var bindingExpression = BindingOperations.GetBindingExpression(textBox, TextBox.TextProperty);
bindingExpression.UpdateTarget();
Assert.AreEqual("1", textBox.Text);
textBox.SetCurrentValue(TextBox.TextProperty, "2");
Assert.AreEqual("1", fakeVm.Value);
bindingExpression.UpdateSource();
Assert.AreEqual("2", fakeVm.Value);
}
示例2: InitView
private EitherControl InitView(Lifetime lifetime, OptionsSettingsSmartContext settings)
{
var grid = new Grid { Background = SystemColors.ControlBrush };
grid.ColumnDefinitions.Add(new ColumnDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition());
var margin = new Thickness(3);
var label = new Label { Content = "Configuration:", Margin = margin };
var text = new TextBox { AcceptsReturn = true, Margin = margin };
settings.SetBinding<OrderUsingsSettings, string>(
lifetime,
x => x.OrderSpecificationXml,
text,
TextBox.TextProperty);
Grid.SetRow(text, 1);
Grid.SetColumnSpan(text, 3);
var buttonPadding = new Thickness(3);
var resetButton = new Button
{
Content = "Reset",
Margin = margin,
Padding = buttonPadding
};
resetButton.Click += (s, e) => text.SetCurrentValue(TextBox.TextProperty, string.Empty);
Grid.SetColumn(resetButton, 1);
var addBasicButton = new Button
{
Content = "Create basic configuration",
Margin = margin,
Padding = buttonPadding
};
addBasicButton.Click += (s, e) =>
{
var asm = typeof(OrderUsingsOptionsPage).Assembly;
Stream stream = asm.GetManifestResourceStream("OrderUsings.ReSharper.Settings.DefaultConfiguration.xml");
if (stream != null)
{
using (var reader = new StreamReader(stream))
{
text.SetCurrentValue(TextBox.TextProperty, reader.ReadToEnd());
}
}
};
Grid.SetColumn(addBasicButton, 2);
grid.Children.Add(label);
grid.Children.Add(text);
grid.Children.Add(resetButton);
grid.Children.Add(addBasicButton);
return grid;
}