本文整理汇总了C#中System.Windows.Controls.TextBox.BeginInit方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.BeginInit方法的具体用法?C# TextBox.BeginInit怎么用?C# TextBox.BeginInit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.TextBox
的用法示例。
在下文中一共展示了TextBox.BeginInit方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TextBox
public void SettingTheAttachedPropertyToTheNameOfABoundPropertyOnANonInitializedElementDoesNotAddValidatorRuleToTheReferencedBinding()
{
var textBox = new TextBox();
textBox.BeginInit();
var binding = new Binding("ValidatedStringProperty")
{
Mode = BindingMode.OneWayToSource,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
BindingOperations.SetBinding(textBox, TextBox.TextProperty, binding);
Validate.SetBindingForProperty(textBox, "Text");
Assert.AreEqual(0, binding.ValidationRules.OfType<ValidatorRule>().Count());
}
示例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: GetElement
public override FrameworkElement GetElement(string fileName)
{
var maxWidth = SystemParameters.WorkArea.Width - 100;
var maxHeight = SystemParameters.WorkArea.Height - 100;
var contents = File.ReadAllBytes(fileName);
var encoding = DetectEncoding(contents);
var textBox = new TextBox();
textBox.BeginInit();
textBox.Width = maxWidth / 2;
textBox.Height = maxHeight / 2;
textBox.Text = encoding.GetString(contents);
textBox.IsReadOnly = true;
textBox.IsReadOnlyCaretVisible = false;
textBox.FontFamily = new FontFamily("Consolas");
textBox.FontSize = 13;
textBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
textBox.EndInit();
return textBox;
}
示例4: AttachingValidationToPropertyWithPriorityBindingAddsRulesToTheLeafLevelBindings
public void AttachingValidationToPropertyWithPriorityBindingAddsRulesToTheLeafLevelBindings()
{
var textBox = new TextBox();
textBox.BeginInit();
var binding1 = new Binding("ValidatedStringProperty")
{
Mode = BindingMode.OneWayToSource,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
var binding2 = new Binding("ValidatedStringProperty")
{
Mode = BindingMode.OneWayToSource,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
BindingOperations.SetBinding(
textBox,
TextBox.TextProperty,
new PriorityBinding
{
Bindings = { binding1, binding2 }
});
textBox.EndInit();
Validate.SetBindingForProperty(textBox, "Text");
Assert.AreEqual(1, binding1.ValidationRules.OfType<ValidatorRule>().Count());
Assert.AreEqual(1, binding2.ValidationRules.OfType<ValidatorRule>().Count());
}
示例5: SettingTheAttachedPropertyTheNameOfAnDependencyPropertyWithAComplexPathBindingThrows
public void SettingTheAttachedPropertyTheNameOfAnDependencyPropertyWithAComplexPathBindingThrows()
{
var textBox = new TextBox();
textBox.BeginInit();
BindingOperations.SetBinding(textBox, TextBox.TextProperty, new Binding("Complex.Path"));
textBox.EndInit();
Validate.SetBindingForProperty(textBox, "Text");
}
示例6: SettingTheAttachedPropertyTheNameOfAnUnboundDependencyPropertyThrows
public void SettingTheAttachedPropertyTheNameOfAnUnboundDependencyPropertyThrows()
{
var textBox = new TextBox();
textBox.BeginInit();
textBox.EndInit();
Validate.SetBindingForProperty(textBox, "Text");
}
示例7: SettingTheAttachedPropertyToAValueThatIsNotADependencyPropertyNameThrows
public void SettingTheAttachedPropertyToAValueThatIsNotADependencyPropertyNameThrows()
{
var textBox = new TextBox();
textBox.BeginInit();
textBox.EndInit();
Validate.SetBindingForProperty(textBox, "InvalidPropertyName");
}
示例8: CanSetARulesetNameAfterSettingTheBindingForPropertyProperty
public void CanSetARulesetNameAfterSettingTheBindingForPropertyProperty()
{
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");
Validate.SetUsingRulesetName(textBox, "Ruleset");
var rule = binding.ValidationRules.OfType<ValidatorRule>().FirstOrDefault();
Assert.AreEqual("Ruleset", rule.RulesetName);
}
示例9: CanSetAValidationSpecificationSourceBeforeSettingTheBindingForPropertyProperty
public void CanSetAValidationSpecificationSourceBeforeSettingTheBindingForPropertyProperty()
{
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.SetUsingSource(textBox, ValidationSpecificationSource.Attributes);
Validate.SetBindingForProperty(textBox, "Text");
var rule = binding.ValidationRules.OfType<ValidatorRule>().FirstOrDefault();
Assert.AreEqual(ValidationSpecificationSource.Attributes, rule.ValidationSpecificationSource);
}
示例10: BindingForPropertyPropertyNamedInAttachedProperyIsValidatedForValidValue
public void BindingForPropertyPropertyNamedInAttachedProperyIsValidatedForValidValue()
{
var instance = new ValidatedObject();
var textBox = new TextBox();
textBox.BeginInit();
textBox.DataContext = instance;
var binding = new Binding("ValidatedStringProperty")
{
Mode = BindingMode.OneWayToSource,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
ValidatesOnExceptions = true
};
PresentationTraceSources.SetTraceLevel(binding, PresentationTraceLevel.High);
BindingOperations.SetBinding(textBox, TextBox.TextProperty, binding);
textBox.EndInit();
Validate.SetBindingForProperty(textBox, "Text");
Assert.IsFalse(SWC.Validation.GetHasError(textBox));
textBox.Text = "aaaaaaaa";
Assert.IsFalse(SWC.Validation.GetHasError(textBox));
}
示例11: ChangingTheAttachedPropertyRemovesTheValidationRule
public void ChangingTheAttachedPropertyRemovesTheValidationRule()
{
var textBox = new TextBox();
textBox.BeginInit();
var binding1 = new Binding("ValidatedIntProperty")
{
Mode = BindingMode.OneWayToSource,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
BindingOperations.SetBinding(textBox, TextBox.MaxLinesProperty, binding1);
var binding2 = new Binding("ValidatedIntProperty")
{
Mode = BindingMode.OneWayToSource,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
BindingOperations.SetBinding(textBox, TextBox.MaxLengthProperty, binding2);
textBox.EndInit();
Validate.SetBindingForProperty(textBox, "MaxLines");
Assert.AreEqual(1, binding1.ValidationRules.OfType<ValidatorRule>().Count());
Assert.AreEqual(0, binding2.ValidationRules.OfType<ValidatorRule>().Count());
Validate.SetBindingForProperty(textBox, "MaxLength");
Assert.AreEqual(0, binding1.ValidationRules.OfType<ValidatorRule>().Count());
Assert.AreEqual(1, binding2.ValidationRules.OfType<ValidatorRule>().Count());
}