本文整理汇总了C#中System.Windows.Controls.TextBox.ClearValue方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.ClearValue方法的具体用法?C# TextBox.ClearValue怎么用?C# TextBox.ClearValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.TextBox
的用法示例。
在下文中一共展示了TextBox.ClearValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetText2
public void SetText2 ()
{
TextBox box = new TextBox { Text = "Blah" };
Assert.AreEqual ("Blah", box.GetValue (TextBox.TextProperty), "#1");
box.SetValue (TextBox.TextProperty, null);
Assert.AreEqual ("", box.GetValue (TextBox.TextProperty), "#2");
box.Text = "o hi";
box.ClearValue (TextBox.TextProperty);
Assert.AreEqual ("", box.GetValue (TextBox.TextProperty), "#3");
}
示例2: ClearingTheAttachedPropertyRemovesTheValidationRule
public void ClearingTheAttachedPropertyRemovesTheValidationRule()
{
var textBox = new TextBox();
textBox.BeginInit();
var binding = new Binding("ValidatedStringProperty")
{
Mode = BindingMode.OneWayToSource,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
BindingOperations.SetBinding(textBox, TextBox.TextProperty, binding);
textBox.EndInit();
Validate.SetBindingForProperty(textBox, "Text");
Assert.AreEqual(1, binding.ValidationRules.OfType<ValidatorRule>().Count());
textBox.ClearValue(Validate.BindingForPropertyProperty);
Assert.AreEqual(0, binding.ValidationRules.OfType<ValidatorRule>().Count());
}
示例3: RenderEditItemField
//.........这里部分代码省略.........
TimePicker timePicker = new TimePicker() { DataContext = container, MinWidth = minWidth, IsTabStop = true };
// set up two-way data binding so that we don't have to pick up the new value in the event handler
timePicker.SetBinding(TimePicker.ValueProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });
timePicker.ValueChanged += new EventHandler<DateTimeValueChangedEventArgs>(delegate
{
folder.NotifyPropertyChanged("FirstDue");
folder.NotifyPropertyChanged("FirstDueColor");
});
timePicker.TabIndex = tabIndex++;
EditStackPanel.Children.Add(timePicker);
break;
case DisplayTypes.Checkbox:
CheckBox cb = new CheckBox() { DataContext = container, IsTabStop = true };
cb.SetBinding(CheckBox.IsCheckedProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });
cb.TabIndex = tabIndex++;
EditStackPanel.Children.Add(cb);
break;
case DisplayTypes.TagList:
TextBox taglist = new TextBox() { MinWidth = minWidth, IsTabStop = true };
taglist.KeyUp += new KeyEventHandler(TextBox_KeyUp);
taglist.TabIndex = tabIndex++;
RenderEditItemTagList(taglist, (Item) container, pi);
EditStackPanel.Children.Add(taglist);
break;
case DisplayTypes.ImageUrl:
// TODO: wire up to picture picker, and upload to an image service
break;
case DisplayTypes.LinkArray:
tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Url } } };
tb.AcceptsReturn = true;
tb.TextWrapping = TextWrapping.Wrap;
tb.Height = 150;
tb.TabIndex = tabIndex++;
tb.ClearValue(TextBox.TextProperty);
if (!String.IsNullOrEmpty((string) currentValue))
{
try
{
var linkList = JsonConvert.DeserializeObject<List<Link>>((string)currentValue);
tb.Text = String.Concat(linkList.Select(l => l.Name != null ? l.Name + "," + l.Url + "\n" : l.Url + "\n").ToList());
}
catch (Exception)
{
}
}
tb.LostFocus += new RoutedEventHandler(delegate
{
// the expected format is a newline-delimited list of Name, Url pairs
var linkArray = tb.Text.Split(new char[] { '\r','\n' }, StringSplitOptions.RemoveEmptyEntries);
var linkList = new List<Link>();
foreach (var link in linkArray)
{
var nameval = link.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (nameval.Length == 0)
continue;
if (nameval.Length == 1)
linkList.Add(new Link() { Url = nameval[0].Trim() });
else
linkList.Add(new Link() { Name = nameval[0].Trim(), Url = nameval[1].Trim() });
}
var json = JsonConvert.SerializeObject(linkList);
pi.SetValue(container, json, null);
});
EditStackPanel.Children.Add(tb);
break;
case DisplayTypes.Hidden:
示例4: clearTextBox
private void clearTextBox(TextBox text)
{
if (text.Text != String.Empty) text.ClearValue(TextBox.TextProperty);
}