本文整理汇总了C#中TextBox.ApplyTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.ApplyTemplate方法的具体用法?C# TextBox.ApplyTemplate怎么用?C# TextBox.ApplyTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextBox
的用法示例。
在下文中一共展示了TextBox.ApplyTemplate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Typing_Beginning_With_0_Should_Not_Modify_Text_When_Bound_To_Int
public void Typing_Beginning_With_0_Should_Not_Modify_Text_When_Bound_To_Int()
{
using (UnitTestApplication.Start(Services))
{
var source = new Class1();
var target = new TextBox
{
DataContext = source,
Template = CreateTemplate(),
};
target.ApplyTemplate();
target.Bind(TextBox.TextProperty, new Binding(nameof(Class1.Foo), BindingMode.TwoWay));
Assert.Equal("0", target.Text);
target.CaretIndex = 1;
target.RaiseEvent(new TextInputEventArgs
{
RoutedEvent = InputElement.TextInputEvent,
Text = "2",
});
Assert.Equal("02", target.Text);
}
}
示例2: Setter_Exceptions_Should_Set_Error_Pseudoclass
public void Setter_Exceptions_Should_Set_Error_Pseudoclass()
{
using (UnitTestApplication.Start(Services))
{
var target = new TextBox
{
DataContext = new ExceptionTest(),
[!TextBox.TextProperty] = new Binding(nameof(ExceptionTest.LessThan10), BindingMode.TwoWay),
Template = CreateTemplate(),
};
target.ApplyTemplate();
Assert.False(target.Classes.Contains(":error"));
target.Text = "20";
Assert.True(target.Classes.Contains(":error"));
target.Text = "1";
Assert.False(target.Classes.Contains(":error"));
}
}
示例3: Setter_Exceptions_Should_Set_DataValidationErrors
public void Setter_Exceptions_Should_Set_DataValidationErrors()
{
using (UnitTestApplication.Start(Services))
{
var target = new TextBox
{
DataContext = new ExceptionTest(),
[!TextBox.TextProperty] = new Binding(nameof(ExceptionTest.LessThan10), BindingMode.TwoWay),
Template = CreateTemplate(),
};
target.ApplyTemplate();
Assert.Null(target.DataValidationErrors);
target.Text = "20";
Assert.Equal(1, target.DataValidationErrors.Count());
Assert.IsType<InvalidOperationException>(target.DataValidationErrors.Single());
target.Text = "1";
Assert.Null(target.DataValidationErrors);
}
}