FontFamilyComboBox Commit not working on mouse selection

Ribbon for WPF Forum

Posted 6 years ago by eric
Version: 17.2.0664
Platform: .NET 4.7
Environment: Windows 10 (64-bit)
Avatar

Hi,

 

im facing an issue with the FontFamilyComboBox.

 

I have the following code:

  <ribbon:FontFamilyComboBox x:Name="FontFamilyComboBox"
                                   MinWidth="70" 
                                   Margin="2" 
                                           Command="{Binding FontFamilyCommand,
                                                             RelativeSource={RelativeSource Mode=FindAncestor,
                                                             AncestorType=local:FontCustomizer}}"
                             />

 

#Region "FontFamilyCommand"
        Private m_previousFont As String
        Private m_wasPreviewPreviewValueSet As Boolean = False
        ''' <summary>
        ''' Changes the font bold style.
        ''' </summary>
        Private Sub ChangeFontFamily(ByVal inputArg As FontFamilyValueCommandParameter)
            If inputArg IsNot Nothing Then
                If (inputArg.Value IsNot Nothing) AndAlso
                    ((Not Ribbon.Controls.FontFamilyComboBox.IsValidFontFamilyName(inputArg.Value.Source))) Then
                    MessageBox.Show(String.Format("The font family '{0}' does not exist.", inputArg.Value),
                                    "Invalid Font Family",
                                    MessageBoxButton.OK, MessageBoxImage.Exclamation)
                Else

                    Select Case inputArg.Action
                        Case ValueCommandParameterAction.CancelPreview
                            MyFont.FontFamily = m_previousFont
                            m_previousFont = String.Empty
                            m_wasPreviewPreviewValueSet = False

                        Case ValueCommandParameterAction.Commit
                            MyFont.FontFamily = inputArg.Value?.ToString
                            m_previousFont = String.Empty
                            m_wasPreviewPreviewValueSet = False

                        Case ValueCommandParameterAction.Preview
                            If Not m_wasPreviewPreviewValueSet Then
                                m_previousFont = MyFont.FontFamily
                                m_wasPreviewPreviewValueSet = True
                            End If
                            MyFont.FontFamily = inputArg.PreviewValue?.ToString

                    End Select
                End If
            End If

            inputArg.Handled = True
        End Sub
        Private Function FontFamilyCanExecute(ByVal inputArg As FontFamilyValueCommandParameter) As Boolean
            If inputArg IsNot Nothing Then
                If MyFont Is Nothing OrElse
                    String.IsNullOrWhiteSpace(MyFont.FontFamily) Then
                    inputArg.UpdatedValue = Nothing
                Else
                    inputArg.UpdatedValue = Ribbon.Controls.FontFamilyComboBox.GetFontFamily(MyFont.FontFamily)
                End If
                inputArg.Handled = True
            End If

            Return True
        End Function
        ''' <summary>
        ''' Command to change the Bold font style.
        ''' </summary>
        Public ReadOnly Property FontFamilyCommand As _
            New Prism.Commands.DelegateCommand(Of FontFamilyValueCommandParameter)(AddressOf ChangeFontFamily,
                                                                                   AddressOf FontFamilyCanExecute)

#End Region

 

For some reason, using the mouse selection to select a choice from the drop-down font selector will call the ValueCommandParameterAction.CancelPreview case (and not the Commit as i would expect).

 

However using the keyboard to select (focus on the value text, then using the up/down arrows following by a 'Enter') will call commit correctly.

 

What am i doing wrong here?

Comments (1)

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

It's hard to say without debugging it.  I tested our main Document Editor demo and the RichTextBoxExtended.OnFontFamilyExecute method there only gets called with Commit when clicking an item.

Note that in our OnFontFamilyCanExecute method we also set: e.CanExecute = true;

Please check that out and if you still can't figure out the problem, build a new simple sample project that shows the issue and send that to our support address.  Exclude any bin/obj folders from the ZIP you send and rename the .zip file extension so it doesn't get spam blocked.  Thanks!


Actipro Software Support

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.