Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
990
getting a grid to accept return
posted

How do I get a xamdatagrid field to accept returns as part of the input, instead of finishing the edit?

 I can't see a property on XamTextEditor to do this.

Thanks

Parents
  • 990
    posted

    I have a hack if there isn't an elegent solution:

    Style the XamTextEditor to call an event when edit mode starts:

    <my:Field Name="Name">
    <my:Field.Settings>
    <my:FieldSettings EditorType="{x:Type igEditors:XamTextEditor}">
    <my:FieldSettings.EditorStyle>
    <Style TargetType="{x:Type igEditors:XamTextEditor}">
    <EventSetter Event="EditModeStarted" Handler="EditStarted" />
    </Style>
    </my:FieldSettings.EditorStyle>
    </my:FieldSettings>
    </my:Field.Settings>
    </my:Field>


    Then in the event handler, walk the visual tree to find the TextBox that's hanging off XamTextEditor, and set the AcceptReturns property:

    public void EditStarted(object sender, EditModeStartedEventArgs e)
    {
     TextBox b = (TextBox)VisualTreeWalker.FindFirst((Visual)e.Source, typeof(TextBox));
     b.AcceptsReturn = true;
    }

    I haven't included VisualTreeWalker here, but it's simple enough code.

    Any better solution?

    Thanks,

    John

  • 8576
    Offline posted in reply to John
    Hi John -
     
     
    That said, rather than doing what you are doing, I would think you should be able to work around this problem by:
    • creating a Style that targets TextBox and contains a Setter for the AcceptsReturn property
    • adding that style to the Resources of the xamTextEditor
    The TextBox style (with the AcceptsReturn Setter) should get picked up via the standard WPF style resolution when the TextBox embedded in the XamTextEditor gets hydrated.
     
    Joe
     
Reply Children