Browse Source

Use Adorner Focus styling for focused DropDownItem

pull/2122/head
Andrey Kunchev 8 years ago
parent
commit
c4ab664833
  1. 10
      src/Avalonia.Controls/DropDown.cs
  2. 20
      src/Avalonia.Themes.Default/DropDown.xaml
  3. 5
      src/Avalonia.Themes.Default/DropDownItem.xaml
  4. 5
      src/Avalonia.Themes.Default/FocusAdorner.xaml

10
src/Avalonia.Controls/DropDown.cs

@ -165,10 +165,10 @@ namespace Avalonia.Controls
else if (IsDropDownOpen && SelectedIndex < 0 && ItemCount > 0 &&
(e.Key == Key.Up || e.Key == Key.Down))
{
var firstChild = Presenter?.Panel?.Children.FirstOrDefault(c => c.Focusable);
var firstChild = Presenter?.Panel?.Children.FirstOrDefault(c => CanFocus(c));
if (firstChild != null)
{
firstChild.Focus();
FocusManager.Instance?.Focus(firstChild, NavigationMethod.Directional);
e.Handled = true;
}
}
@ -223,7 +223,7 @@ namespace Avalonia.Controls
private void PopupClosed(object sender, EventArgs e)
{
if (Focusable)
if (CanFocus(this))
{
Focus();
}
@ -246,13 +246,15 @@ namespace Avalonia.Controls
if (IsDropDownOpen && selectedIndex != -1)
{
var container = ItemContainerGenerator.ContainerFromIndex(selectedIndex);
if (container != null && container.Focusable)
if (container != null && CanFocus(container))
{
container.Focus();
}
}
}
private bool CanFocus(IControl control) => control.Focusable && control.IsEnabledCore && control.IsVisible;
private void UpdateSelectionBoxItem(object item)
{
var contentControl = item as IContentControl;

20
src/Avalonia.Themes.Default/DropDown.xaml

@ -39,15 +39,17 @@
StaysOpen="False">
<Border BorderBrush="{DynamicResource ThemeBorderMidBrush}"
BorderThickness="1">
<ScrollViewer>
<ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}"
MemberSelector="{TemplateBinding MemberSelector}"
VirtualizationMode="{TemplateBinding VirtualizationMode}"
<AdornerDecorator Margin="-1 -1 0 0">
<ScrollViewer>
<ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}"
MemberSelector="{TemplateBinding MemberSelector}"
VirtualizationMode="{TemplateBinding VirtualizationMode}"
/>
</ScrollViewer>
</ScrollViewer>
</AdornerDecorator>
</Border>
</Popup>
</Grid>
@ -58,4 +60,4 @@
<Style Selector="DropDown:pointerover /template/ Border#border">
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderHighBrush}"/>
</Style>
</Styles>
</Styles>

5
src/Avalonia.Themes.Default/DropDownItem.xaml

@ -4,7 +4,6 @@
<Setter Property="Padding" Value="2"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<ControlTemplate>
<ContentPresenter Name="PART_ContentPresenter"
@ -20,10 +19,6 @@
</Setter>
</Style>
<Style Selector="DropDownItem:focus /template/ ContentPresenter">
<Setter Property="BorderBrush" Value="{DynamicResource ThemeAccentBrush3}"/>
</Style>
<Style Selector="DropDownItem:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeControlHighlightMidBrush}"/>
</Style>

5
src/Avalonia.Themes.Default/FocusAdorner.xaml

@ -3,7 +3,8 @@
<FocusAdornerTemplate>
<Rectangle Stroke="Black"
StrokeThickness="1"
StrokeDashArray="1,2"/>
StrokeDashArray="1,2"
Margin="1"/>
</FocusAdornerTemplate>
</Setter>
</Style>
</Style>

Loading…
Cancel
Save