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?