Why "TextWrapping" automatically adds to XAML when inserting a TextBox

After dragging and dropping some control like TextBox in WPF window, you can see below line in XAML

<TextBox ... TextWrapping="Wrap" Text="TextBox" /> 

These properties are automatically inserted into XAML! Just some special property inserted in XAML.

Questions:

  • Why are these special properties (for example, TextWrapping or Text for TextBox) automatically added to XAML? (Is there an attribute for this)?
  • I want to inherit a class from a TextBox and prevent the TextWrapping property from TextWrapping automatically added. Is it possible? (Is there an attribute for this)?
  • Is there a solution to select some properties for automatic installation in XAML in design mode (for example, this is TextWrapping TextBox)?
+4
source share
2 answers

What you need is the DefaultInitializer , which determines which default values ​​are set when dragging from the ToolBox to the design view.

 [Feature(typeof(myDefaults))] public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } public class myDefaults : DefaultInitializer { public override void InitializeDefaults(ModelItem item) { item.Name = "test"; } } } 

Dragging this control onto the form then results in

 <local:UserControl1 x:Name="test" Width="100"/> 
+3
source

To set default values ​​for wpf controls (for example, you want all your text fields to be 30 pixels wide by 10 pixels high in 5 pixel increments), you can define styles.

If you look at the sample presented here, you will see how the TextBlock style is defined by default and applies to all text blocks. http://msdn.microsoft.com/en-us/library/ms745683.aspx

 <!--A Style that affects all TextBlocks--> <Style TargetType="TextBlock"> <Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="FontFamily" Value="Comic Sans MS"/> <Setter Property="FontSize" Value="14"/> </Style> 

If you want more designer experience, I would recommend using Blend instead of Visual Studio Designer.

+2
source

Source: https://habr.com/ru/post/1497319/


All Articles