locked
Pixata Stylable Textbox / Problem by using in Modal Windows RRS feed

  • Question

  • Hi,

    i have a Problem with the Pixata stylable TextBox. It´s a little bit difficult to explain in english :-(

    I try to use a modal window for add and edit data. As described in many Posts, there is a big Problem with the Default Enetr-key colsing this modal window

    I´m using Yanns great modal window helper and i have modifyd this code a Little bit to prevent the Default behavior.

    Imports System.ComponentModel
    Imports System.Windows.Controls
    Imports Microsoft.LightSwitch
    Imports Microsoft.LightSwitch.Client
    Imports Microsoft.LightSwitch.Presentation
    Imports Microsoft.LightSwitch.Threading
    Imports Microsoft.LightSwitch.Presentation.Extensions
    
    Public Class clModalWindowHelper
        Public Delegate Function CanCloseFunction() As Boolean
    
        Private _collection As IVisualCollection
        Private _dialogName As String
        Private _entityName As String
        Private _screen As IScreenObject
        Private _window As IContentItemProxy
        Private _entity As IEntityObject
        Private _saveOnClose As Boolean
    
        Private _close As Boolean = False
    
        Public Sub New(
                      ByVal visualCollection As IVisualCollection _
                      , ByVal dialogName As String _
                      , Optional entityName As String = "")
    
            _collection = visualCollection
            _dialogName = dialogName
            _entityName = If(entityName <> "", entityName, _collection.Details.GetModel.ElementType.Name)
            _screen = _collection.Screen
        End Sub
    
        Public Sub Initialize(
            Optional hasCloseButton As Boolean = True _
            , Optional saveOnClose As Boolean = False _
            , Optional width As Integer = 400 _
            , Optional height As Integer = 400 _
                                                )
    
            _window = _screen.FindControl(_dialogName)
            _saveOnClose = saveOnClose
    
            AddHandler _window.ControlAvailable,
                Sub(s As Object, e As ControlAvailableEventArgs)
                    Dim window = DirectCast(e.Control, ChildWindow)
    
                    window.HasCloseButton = hasCloseButton
    
                    window.Width = width
                    window.Height = height
    
    
                    AddHandler window.Closed, _
                        Sub(s1 As Object, eq As EventArgs)
                            DialogClosed(s1)
                        End Sub
    
                    AddHandler window.Closing, _
                        Sub(s1 As Object, eq As CancelEventArgs)
                            If _close Then
                                eq.Cancel = False
                            Else
                                eq.Cancel = True
    
                            End If
                        End Sub
                End Sub
        End Sub
    
        Public Function CanAdd() As Boolean
            Return (_collection.CanAddNew = True)
        End Function
    
        Public Function CanView() As Boolean
            Return (_collection.SelectedItem IsNot Nothing)
        End Function
    
        Public Sub AddEntity()
            Dim result As IEntityObject = Nothing
    
            _window.DisplayName = String.Format("Add {0}", _entityName)
            _collection.AddNew()
    
            OpenModalWindow()
        End Sub
    
        Public Sub ViewEntity()
            _window.DisplayName = String.Format("View {0}", _entityName)
            OpenModalWindow()
        End Sub
    
        Private Sub OpenModalWindow()
            _entity = TryCast(_collection.SelectedItem, IEntityObject)
            _screen.OpenModalWindow(_dialogName)
        End Sub
    
        Public Sub DialokOK()
            If (_entity IsNot Nothing) Then
                _close = True
                _screen.CloseModalWindow(_dialogName)
                _close = False
            End If
        End Sub
    
        Public Sub DialogCancel()
            If (_entity IsNot Nothing) Then
                _close = True
                _screen.CloseModalWindow(_dialogName)
                DiscardChanges()
                _close = False
            End If
        End Sub
    
        Public Sub DialogClosed(sender As Object)
            Dim window = DirectCast(sender, ChildWindow)
    
            Select Case window.DialogResult.HasValue
                Case True
                    If (_saveOnClose = True) Then
                        _screen.Details.Dispatcher.BeginInvoke(Sub()
                                                                   _screen.Save()
                                                               End Sub)
    
                    End If
    
                Case False
                    DiscardChanges()
            End Select
        End Sub
    
        Private Sub DiscardChanges()
            If (_entity IsNot Nothing) Then
                _entity.Details.DiscardChanges()
            End If
        End Sub
    
    End Class
    
    
    

    As you can see, i use a _close boolean value to check, if the closing event is fired by Press the enter key or by pressing a save button.

    It seems, this is working. But i have a Problem, if i use some text (multiline Boxes). If i use a pixata stylable TextBox, after pressing the enter key, the Focus for Input is lost and the box is marked itself. I must click with the mouse another time in the box to enter some other text in a new line.

    If i use a LS-Textfield, by pressing the enter key, a new line is inserted and the Focus is already set to Input text.

    Maybe, for the pixate TextBox, there is any Workaround. But i think, it´s a generally Problem with the modal window. I can´t understand, that make a modal window with 'normal' behavior like Input data in different fields is so difficult.

    Regards

    Thomas

     


    Thomas Bach

    Thursday, April 4, 2013 4:56 PM

Answers

  • Hi Mr Yossu,

    thanks for the reply. I understand the behavior, but it´s not clear to me, why it works (also with multiline) with a normal TextBox like in my sample.

    I don't know how the LS implemented the multiline feature in the built-in textbox, and it may be that they found a way to capture the Enter before the modal window code does. My control uses the standard Silverlight textbox, and it looks like the modal window code is grabbing the Enter before the textbox gets chance.

    I´m capturing the Enter key because it´s interpreted as OK in a modal window. If there´s another solution to prevent closing of modal window by presssing Enter, i´ll try that.

    Well, as I explained before, you have a conflict of interest if you have a multiline textbox (which accepts Enter), but you want the Enter key to mean close the window. If you want the multiline feature, then I would suggest disabling the Enter-means-close code for the modal window.

    Hope this helps.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    • Marked as answer by Thomas Bach Wednesday, April 10, 2013 6:21 PM
    Wednesday, April 10, 2013 1:59 PM

All replies

  • Hi Thomas,

    I'm a bit confused here. Does a normal textbox work OK, or do you have the same problem with that?

    Either way, please can you create the smallest possible sample solution that shows the problem, clean it, zip it up and send it to me at mryossu@hotmail.com - I'll have a look and see if I can see what the problem is.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Thursday, April 4, 2013 5:17 PM
  • Hi Mr Yossu,

    yes. it´s right. The normal TextBox works OK. I´ll made a small sample Project tomorrow.

    Regards

    Thomas


    Thomas Bach

    Thursday, April 4, 2013 5:20 PM
  • Mr Yossu,

    i´ve send you a small demo Project (VS 2012).

    It´s only one table and one Screen. In the table, i have 3 fields (Name and two text)

    In the Screen, there is a grid with theses datas and also a button to call the modal window. In the modal window the first TextBox is 'normal' and the second 'pixata'.

    If you enter data in the 'normal' box, you can use enter-key to insert a new line.

    In the 'pixata' box, by pressing enter, the Focus is lost.

    Regards

    Thomas


    Thomas Bach

    Friday, April 5, 2013 8:48 AM
  • Hello Thomas,

    The problem seems to be related to the fact that you are capturing the Enter key to close the window. That would work fine if you didn't have any multi-line textboxes. However, as you have set the Pixata one to be multiline, you want the user to be able to press Enter whilst in that textbox and not have this captured by the modal window, but the code is capturing the Enter, and so taking focus away from the textbox.

    I suspect you would see the same behaviour if you were to do this in a plain Silverlight project, and add a normal Textbox, set to be multiline. It's nothing to do with my control specifically, just that this happens to allow multiline, which the regular one doesn't, so you are seeing the problem here.

    If you want to allow a multiline textbox, you would need to disable the feature where pressing Enter is interpreted as the same as clicking the OK button. That would be the same in any environment, WPF, Silverlight, WinForms, Lightswitch, etc. It's nothing to do with Lightswitch, modal windows or my textbox. It's simply a conflict of two different results when you press Enter. You have to choose one or the other.

    Hope this helps.

    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Monday, April 8, 2013 1:38 PM
  • Hi Mr Yossu,

    thanks for the reply. I understand the behavior, but it´s not clear to me, why it works (also with multiline) with a normal TextBox like in my sample.

    I´m capturing the Enter key because it´s interpreted as OK in a modal window. If there´s another solution to prevent closing of modal window by presssing Enter, i´ll try that.

    Regards

    Thomas 


    Thomas Bach

    Wednesday, April 10, 2013 11:48 AM
  • Hi Mr Yossu,

    thanks for the reply. I understand the behavior, but it´s not clear to me, why it works (also with multiline) with a normal TextBox like in my sample.

    I don't know how the LS implemented the multiline feature in the built-in textbox, and it may be that they found a way to capture the Enter before the modal window code does. My control uses the standard Silverlight textbox, and it looks like the modal window code is grabbing the Enter before the textbox gets chance.

    I´m capturing the Enter key because it´s interpreted as OK in a modal window. If there´s another solution to prevent closing of modal window by presssing Enter, i´ll try that.

    Well, as I explained before, you have a conflict of interest if you have a multiline textbox (which accepts Enter), but you want the Enter key to mean close the window. If you want the multiline feature, then I would suggest disabling the Enter-means-close code for the modal window.

    Hope this helps.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    • Marked as answer by Thomas Bach Wednesday, April 10, 2013 6:21 PM
    Wednesday, April 10, 2013 1:59 PM
  • Now, i understand.

    But i can´t find any solution (also in theforums) to diabling the automatic Close of modal Windows by pressing the enter key.

    Nevertheless, many thanks for your help


    Thomas Bach

    Wednesday, April 10, 2013 6:22 PM