I'm creating custom control derived from ComboBox that has Intellisense-like feature. When user presses Ctrl+Space popup is shown. I've got 2 types of popup: one with a listbox inside and second with XamMonthCalendar. When popup is opened I'm moving focus to ListBox or XamMonthCalendar by calling Focus() method so user can select value by using keyboard. In case with ListBox it works fine, but with with XamMonthCalendar it doesn't - control doesn't receive focus.
Popups are defined in xaml in the same way:
<Popup x:Name="PART_PopupKeywordList" Grid.Column="0" AllowsTransparency="True" Placement="Bottom" IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsKeywordDropDownOpen}" StaysOpen="False" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Focusable="False"> <luna:SystemDropShadowChrome Color="Transparent"> <Border Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" BorderBrush="{DynamicResource {x:Static igres:RibbonBrushKeys.SubMenuHeaderPopUpBorderDarkFillKey}}" BorderThickness="1" CornerRadius="2,2,2,2" SnapsToDevicePixels="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto"> <ListBox x:Name="PART_ListBoxKeywordList" BorderBrush="Transparent" Margin="0,0,4,0" KeyboardNavigation.DirectionalNavigation="Cycle" FocusVisualStyle="{x:Null}"/> </Border> </luna:SystemDropShadowChrome> </Popup>
<Popup x:Name="PART_PopupMonthCalendar" Grid.Column="1" AllowsTransparency="True" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" StaysOpen="False" Focusable="False"> <luna:SystemDropShadowChrome Color="Transparent"> <Border Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" BorderBrush="{DynamicResource {x:Static igres:RibbonBrushKeys.SubMenuHeaderPopUpBorderDarkFillKey}}" BorderThickness="1" CornerRadius="2,2,2,2" SnapsToDevicePixels="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto"> <igmc:XamMonthCalendar x:Name="PART_MonthCalendar" SelectionType="Single" AutoAdjustCalendarDimensions="False"/> </Border> </luna:SystemDropShadowChrome> </Popup>
In the code I subscribe to a Popup.Opened event:
private void KeywordPopup_Opened(object sender, EventArgs e) {
// keywordList is a ListBox
if (_keywordList != null) { _keywordList.Focus(); } }
private void MonthCalendarPopup_Opened(object sender, EventArgs e) {
// _monthCalendar is a XamMonthCalendar if (_monthCalendar != null) { _monthCalendar.Focus(); }}
By default when the xamMonthCalendar gets keyboard focus it will shift focus to the CalendarItem that represents the ActiveDate so while the control itself won't have keyboard focus, focus will be within the control. Is that not the behavior you are seeing?
I assume, that default ActiveDate is today, so user is able change it arrows on keyboard/ But in my case calendar doesn't have focus at all after I call its Focus method.