The subject says it all: how do I allow the user to press "Enter" in a multiline XamTextEditor? Currently in a multiline XamTextEditor if I press "Enter" instead of going to a second line, the focus simply moves out of the XamTextEditor.
A regular WPF textbox has a property called "AcceptsReturn" but I don't find it in a XamTextEditor. I'm running 'NetAdvantage for WPF 2007 Vol. 2'.
very fast solution:
<igEditors:XamTextEditor > <igEditors:XamTextEditor.Resources> <Style TargetType="{x:Type TextBox}"> <Setter Property="AcceptsReturn" Value="True"/> </Style> </igEditors:XamTextEditor.Resources></igEditors:XamTextEditor>
Sure, no problem. Just be careful when using Blend to create control template for a Xam***Editor control - when we were using Blen 1.0 SP1 some of the XAML was not being properly copied. It seems better with Blend 2.0, but you may want to double check it (Infragisitcs provides the bare control templates in C:\Program Files\Infragistics\NetAdvantage for WPF 2007 Vol. 2\DefaultStyles).
For reference and for those who don't use Blend, here's some sample XAML (notice the AcceptsReturn property):
<Window.Resources> <ControlTemplate x:Key="XamTextEditorControlTemplate2" TargetType="{x:Type igEditors:XamTextEditor}"> <Border x:Name="MainBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <TextBox Background="#00FFFFFF" BorderBrush="#00FFFFFF" BorderThickness="0,0,0,0" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" ContextMenu="{TemplateBinding ContextMenu}" x:Name="PART_FocusSite" HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}" IsReadOnly="{TemplateBinding ReadOnly}" VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}" MaxLength="{Binding Path=ValueConstraint.MaxLength, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" Text="{Binding Path=Text, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}" TextAlignment="{TemplateBinding TextAlignmentResolved}" TextWrapping="{TemplateBinding TextWrapping}" AcceptsReturn="True"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsInEditMode" Value="True"> <Setter Property="IsTabStop" Value="False"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Window.Resources>
Thanks for sharing your design tips using Blend!
1) Edit an “Edit Template” (right click on the control instance and choose Edit Other Templates > Edit EditTemplate > Edit a Copy…)2) You’ll find a textbox inside the control template called “PART_FocusSite”3) Set the “AcceptsReturn” to true (checked). You’ll find it by expanding the “Text” section. That’s it , you can now have a XamTextEditor with vertical scroll bars when in edit mode (set “VerticalScrollBarVisible” to visible in the control, not the template), that accepts “Enter” for editing multiple lines. You can apply the style (the edited “edit control template”) to all XamTextEditors that need support for “Enter”.