Missing Multiline?


Developers used to working with the System.Windows.Form.TextBox control will be familiar with the Multiline property. This property is used to control whether a text box shows multiple lines, and then you can use other properties to tweak how it behaves in this mode. The Avalon TextBox has no such property. What happened?


Well, it turns out that it provides support for the same scenarios, but properties 'just work' without taking any single-line or multi-line controls into consideration. The AcceptsReturn property, for example, can be used to determine whether the user can press Enter to press multiple lines (you can always enter multiple lines by just assigning text to the Text property). The Wrap property controls whether text wraps into multiple lines, regardless of whether the user can enter line breaks.


This allows a nifty setup for long strings like URLs that are still a single-line thing, but you don't need to make your users scroll to see all content. Just set AcceptsReturn to false and Wrap to true.


Finally, to give you a little something to play with, and to show off how cool data binding is, here's a bit of XAML that lets you interactively play with some of the TextBox properties.


<StackPanel xmlns='http://schemas.microsoft.com/winfx/avalon/2005'>
 <CheckBox Name='AcceptsReturnBox'>AcceptsReturn</CheckBox>
 <CheckBox Name='IsReadOnlyBox'>IsReadOnly</CheckBox>
 <CheckBox Name='WrapBox'>Wrap</CheckBox>
 <ComboBox Name='BackgroundBox'>
  <SolidColorBrush Color='White' />
  <SolidColorBrush Color='Green' />
  <SolidColorBrush Color='Blue' />
  <LinearGradientBrush>
   <LinearGradientBrush.GradientStops>
    <GradientStop Color='Yellow' Offset='0' />
    <GradientStop Color='Red' Offset='1' />
   </LinearGradientBrush.GradientStops>
  </LinearGradientBrush>
 </ComboBox>
 <TextBox Name='TargetBox' FontSize='32'>
  <TextBox.AcceptsReturn>
   <Binding ElementName='AcceptsReturnBox' Path='IsChecked' />
  </TextBox.AcceptsReturn>
  <TextBox.IsReadOnly>
   <Binding ElementName='IsReadOnlyBox' Path='IsChecked' />
  </TextBox.IsReadOnly>
  <TextBox.Wrap>
   <Binding ElementName='WrapBox' Path='IsChecked' />
  </TextBox.Wrap>
  <TextBox.Background>
   <Binding ElementName='BackgroundBox' Path='SelectedItem' />
  </TextBox.Background>
 </TextBox>
</StackPanel>



Comments (2)

  1. Putting Constants in your XAML File? x:Static Is Your Friend.

    Building an Avalon application: Part…

  2. Andrey Skvortsov says:

    All this is nice but how about ContentAlign="Right"?It seems there’s no way to right align text in textbox.

Skip to main content