diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-09-14 16:49:01 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-09-14 16:49:01 +0300 |
| commit | 0e32cd5fb97c40624d5323cb265d070b2140d2bc (patch) | |
| tree | 816067dbc24cd56fee2b24d113be90e84e593fa1 /Software/Visual_Studio | |
| parent | 13afc37417c9281f5fbaacd174fd151d793151eb (diff) | |
| download | Tango-0e32cd5fb97c40624d5323cb265d070b2140d2bc.tar.gz Tango-0e32cd5fb97c40624d5323cb265d070b2140d2bc.zip | |
Refactored SearchComboBox !!!
Diffstat (limited to 'Software/Visual_Studio')
3 files changed, 109 insertions, 254 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 40710ea21..8f02749da 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -1673,7 +1673,17 @@ namespace Tango.MachineStudio.Developer.ViewModels { await Task.Factory.StartNew(() => { - InvalidateLiquidFactorsAndProcessTables(); + try + { + IsFree = false; + InvalidateLiquidFactorsAndProcessTables(); + } + catch + {} + finally + { + IsFree = true; + } }); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml index 4e8a0a1d7..f5f64f992 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml @@ -10,7 +10,7 @@ xmlns:local="clr-namespace:Tango.MachineStudio.Common.Resources" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"> <ResourceDictionary.MergedDictionaries> - + <!--WPF Extended Toolkit--> <!--<ResourceDictionary Source="pack://application:,,,/Xceed.Wpf.Toolkit;component/Themes/Generic/Brushes.xaml"/> <ResourceDictionary Source="pack://application:,,,/Xceed.Wpf.Toolkit;component/Themes/Generic/Buttons.xaml"/> @@ -29,7 +29,9 @@ <!--<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml"> </ResourceDictionary> - --><!--Material Design--><!-- + --> + <!--Material Design--> + <!-- <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml"> </ResourceDictionary>--> <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml"> @@ -66,7 +68,7 @@ <FontFamily x:Key="digital-7">../Fonts/#digital-7</FontFamily> <FontFamily x:Key="flexo">../Fonts/#flexo</FontFamily> </ResourceDictionary> - + <!--Images--> <ResourceDictionary> <BitmapImage x:Key="MachineBig" UriSource="../Images/machine_new.png"></BitmapImage> @@ -769,214 +771,45 @@ </Style> <Style TargetType="{x:Type controls:SearchComboBox}" BasedOn="{StaticResource MaterialDesignComboBox}"> - <Setter Property="Background" Value="Transparent"/> + <Setter Property="KeyboardNavigation.DirectionalNavigation" Value="Once"></Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type controls:SearchComboBox}"> - <Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True"> - <Grid x:Name="InnerRoot"> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="*" /> - <ColumnDefinition Width="0" MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" /> - </Grid.ColumnDefinitions> - <ToggleButton x:Name="SearchToggleButton" Grid.ColumnSpan="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" IsChecked="{Binding IsOpened, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{x:Null}"> - <ToggleButton.Template> - <ControlTemplate TargetType="ToggleButton"> - <Grid> - <Border x:Name="ToggleTemplateRoot" - Background="{TemplateBinding Background}" - BorderBrush="{TemplateBinding BorderBrush}" - BorderThickness="{TemplateBinding BorderThickness}"> - <Border x:Name="splitBorder" - Margin="0" - HorizontalAlignment="Right" - VerticalAlignment="Center" - BorderBrush="Transparent" - BorderThickness="0"> - <Path x:Name="arrow" - Width="8" Height="8" - Margin="0" - Stretch="Uniform" - HorizontalAlignment="Right" - VerticalAlignment="Center" - Data="M7,10L12,15L17,10H7Z" - Fill="{TemplateBinding BorderBrush}" /> - </Border> - </Border> - </Grid> - <ControlTemplate.Triggers> - <MultiDataTrigger> - <MultiDataTrigger.Conditions> - <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true" /> - <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false" /> - </MultiDataTrigger.Conditions> - </MultiDataTrigger> - <MultiDataTrigger> - <MultiDataTrigger.Conditions> - <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true" /> - <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true" /> - </MultiDataTrigger.Conditions> - <Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}" /> - </MultiDataTrigger> - <Trigger Property="IsPressed" Value="true"> - <Setter TargetName="arrow" Property="Fill" Value="{DynamicResource PrimaryHueDarkBrush}" /> - </Trigger> - <Trigger Property="IsEnabled" Value="false"> - <Setter TargetName="arrow" Property="Fill" Value="{DynamicResource MaterialDesignCheckBoxDisabled}" /> - </Trigger> - <MultiDataTrigger> - <MultiDataTrigger.Conditions> - <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false" /> - <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false" /> - </MultiDataTrigger.Conditions> - <Setter TargetName="ToggleTemplateRoot" Property="BorderBrush" Value="Transparent"/> - </MultiDataTrigger> - <MultiDataTrigger> - <MultiDataTrigger.Conditions> - <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false" /> - <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true" /> - </MultiDataTrigger.Conditions> - <Setter TargetName="ToggleTemplateRoot" Property="BorderBrush" Value="Transparent"/> - <Setter TargetName="splitBorder" Property="BorderBrush" Value="{DynamicResource MaterialDesignCheckBoxDisabled}" /> - </MultiDataTrigger> - </ControlTemplate.Triggers> - </ControlTemplate> - </ToggleButton.Template> - </ToggleButton> - <Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" UseLayoutRounding="{TemplateBinding UseLayoutRounding}"> - <Grid x:Name="InputRoot" HorizontalAlignment="Left"> - <ContentPresenter x:Name="contentPresenter" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" IsHitTestVisible="False" /> - <TextBox x:Name="PART_EditableTextBox" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Left" HorizontalContentAlignment="Stretch" Style="{StaticResource MaterialDesignComboBoxEditableTextBox}" CaretBrush="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderBrush}" Visibility="Collapsed" /> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> - <materialDesign:SmartHint x:Name="Hint" - HintProxy="{Binding RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static converters:HintProxyFabricConverter.Instance}}" - FontSize="{TemplateBinding FontSize}" - SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" - UseLayoutRounding="{TemplateBinding UseLayoutRounding}" - UseFloating="{Binding Path=(materialDesign:HintAssist.IsFloating), RelativeSource={RelativeSource TemplatedParent}}" - HintOpacity="{Binding Path=(materialDesign:HintAssist.HintOpacity), RelativeSource={RelativeSource TemplatedParent}}" - Hint="{TemplateBinding materialDesign:HintAssist.Hint}" /> + <Grid> + <DockPanel> + <Grid VerticalAlignment="Center" Margin="15 10 10 10" DockPanel.Dock="Right" Width="10" Height="10"> + <Path Stretch="Uniform" Data="M7,10L12,15L17,10H7Z" Fill="{StaticResource BlackBrush}"> + + </Path> </Grid> - </Grid> - <Line x:Name="DashedLine" Grid.ColumnSpan="2" VerticalAlignment="Bottom" Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Converter={StaticResource InverseBoolToVisConverter}}" StrokeThickness="1.25" StrokeDashArray="1,2.5" StrokeDashCap="Round" X1="0" X2="{Binding ActualWidth, ElementName=SearchToggleButton}" Y1="0" Y2="0" Stroke="{TemplateBinding BorderBrush}" Opacity="0.56" /> - <materialDesign:Underline x:Name="Underline" Grid.ColumnSpan="2" IsActive="{Binding ElementName=PART_EditableTextBox, Path=IsKeyboardFocused}" Visibility="{Binding Path=(materialDesign:TextFieldAssist.DecorationVisibility), RelativeSource={RelativeSource TemplatedParent}}"/> - - <materialDesign:ComboBoxPopup x:Name="PART_Popup" AllowsTransparency="true" HorizontalOffset="0" Tag="{Binding RelativeSource={RelativeSource AncestorType=controls:SearchComboBox}}" IsOpen="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=IsOpened, Mode=TwoWay}" PlacementTarget="{Binding ElementName=templateRoot}" SnapsToDevicePixels="True" UseLayoutRounding="True" Placement="Bottom" PopupAnimation="Fade" VerticalOffset="-10" DefaultVerticalOffset="5" - MinWidth="{Binding ElementName=SearchToggleButton,Path=ActualWidth}" DownVerticalOffset="{Binding ElementName=templateRoot, Path=ActualHeight}" UpVerticalOffset="15" ClassicMode="{Binding Path=(materialDesign:ComboBoxAssist.ClassicMode), RelativeSource={RelativeSource TemplatedParent}}" - MaxHeight="{TemplateBinding MaxDropDownHeight}" UpContentTemplate="{StaticResource PopupContentUpTemplate}" DownContentTemplate="{StaticResource TransparentPopupContentDownTemplate}" ClassicContentTemplate="{StaticResource PopupContentClassicTemplate}" StaysOpen="False" Margin="10 0 0 0"> - <ContentControl> - <Grid> - <Border Opacity="1" Background="{DynamicResource ComboBox.Floating.Background}" Padding="1" BorderThickness="0" BorderBrush="{TemplateBinding BorderBrush}" MaxHeight="{TemplateBinding MaxDropDownHeight}" Margin="0 0 10 10" > - <Border.Effect> - <DropShadowEffect BlurRadius="10" ShadowDepth="5" /> - </Border.Effect> - <DockPanel Margin="5"> - <TextBox x:Name="Search" DockPanel.Dock="Top" Margin="10" Padding="0 5" HorizontalAlignment="Stretch" Text="{Binding RelativeSource={RelativeSource AncestorType=controls:SearchComboBox}, Path=SearchFilter, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Background="{DynamicResource ComboBox.Floating.Background}" IsReadOnly="False" FontSize="14" TextAlignment="Left" VerticalAlignment="Center" VerticalContentAlignment="Center" BorderThickness="0 0 0 2" > - <TextBox.Style> - <Style TargetType="TextBox"/> - </TextBox.Style> - </TextBox> - <ListBox x:Name="list" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=controls:SearchComboBox}, Path = ListItemsSource}" ItemTemplate="{TemplateBinding ItemTemplate}"/> + <ContentControl Focusable="False" FocusVisualStyle="{x:Null}" Content="{TemplateBinding SelectedItem}" ContentTemplate="{TemplateBinding ItemTemplate}"> - </DockPanel> - </Border> - </Grid> </ContentControl> - </materialDesign:ComboBoxPopup> + </DockPanel> + <ToggleButton x:Name="btnToggle" Focusable="False" FocusVisualStyle="{x:Null}" KeyboardNavigation.DirectionalNavigation="Once" Opacity="0" Style="{x:Null}" IsChecked="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=IsOpened,Mode=TwoWay}"> + + </ToggleButton> + + <Popup StaysOpen="False" MinWidth="{Binding ElementName=btnToggle,Path=ActualWidth}" PlacementTarget="{Binding ElementName=btnToggle}" Placement="Bottom" IsOpen="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=IsOpened,Mode=TwoWay}" MaxHeight="{TemplateBinding MaxDropDownHeight}" AllowsTransparency="True"> + <Border Margin="5" Background="{StaticResource WhiteBrush}" CornerRadius="3" Padding="5" MinWidth="{Binding ElementName=btnToggle,Path=ActualWidth}"> + <Border.Effect> + <DropShadowEffect ShadowDepth="0" /> + </Border.Effect> + <DockPanel> + <TextBox x:Name="txt" KeyboardNavigation.DirectionalNavigation="Once" DockPanel.Dock="Top" Margin="10" Padding="0 5" Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=SearchFilter,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"></TextBox> + <ListBox x:Name="list" FocusVisualStyle="{x:Null}" ItemsSource="{TemplateBinding ListItemsSource}" ItemTemplate="{TemplateBinding ItemTemplate}"> + + </ListBox> + </DockPanel> + </Border> + </Popup> </Grid> - </Grid> - <ControlTemplate.Triggers> - <Trigger SourceName="PART_Popup" Property="PopupPlacement" Value="{x:Static materialDesign:ComboBoxPopupPlacement.Classic}"> - <Setter Property="ItemContainerStyle" Value="{StaticResource MaterialDesignComboBoxItemStyle}" /> - </Trigger> - <Trigger SourceName="PART_Popup" Property="IsOpen" Value="True"> - <Setter Property="Background" TargetName="templateRoot" Value="Transparent" /> - </Trigger> - <Trigger Property="IsEnabled" Value="False"> - <Setter TargetName="templateRoot" Property="Opacity" Value="0.56"/> - <Setter TargetName="SearchToggleButton" Property="BorderBrush" Value="Transparent"/> - </Trigger> - <Trigger Property="IsEditable" Value="True"> - <Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible" /> - <Setter TargetName="Underline" Property="Visibility" Value="{Binding Path=(materialDesign:TextFieldAssist.DecorationVisibility), RelativeSource={RelativeSource TemplatedParent}}" /> - <Setter TargetName="contentPresenter" Property="Visibility" Value="Collapsed" /> - </Trigger> - <Trigger Property="materialDesign:HintAssist.IsFloating" Value="True"> - <Setter TargetName="InnerRoot" Property="Margin" Value="0 11.5 0 0" /> - </Trigger> - <MultiTrigger> - <MultiTrigger.Conditions> - <Condition Property="IsEditable" Value="False"/> - <Condition Property="IsDropDownOpen" Value="True"/> - </MultiTrigger.Conditions> - <Setter TargetName="Underline" Property="Visibility" Value="Hidden"/> - <Setter TargetName="SearchToggleButton" Property="BorderBrush" Value="Transparent"/> - </MultiTrigger> - <MultiTrigger> - <MultiTrigger.Conditions> - <Condition SourceName="Hint" Property="IsContentNullOrEmpty" Value="False" /> - <Condition Property="materialDesign:HintAssist.IsFloating" Value="True" /> - <Condition Property="IsKeyboardFocusWithin" Value="True" /> - </MultiTrigger.Conditions> - <Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" /> - <Setter TargetName="Hint" Property="HintOpacity" Value="1" /> - </MultiTrigger> - <MultiTrigger> - <MultiTrigger.Conditions> - <Condition Property="materialDesign:HintAssist.IsFloating" Value="True" /> - <!--<Condition SourceName="Hint" Property="IsHintInFloatingPosition" Value="True" />--> - <Condition Property="IsKeyboardFocusWithin" Value="True" /> - </MultiTrigger.Conditions> - <Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" /> - <Setter TargetName="Hint" Property="HintOpacity" Value="1" /> - </MultiTrigger> - <MultiTrigger> - <MultiTrigger.Conditions> - <Condition SourceName="Hint" Property="IsContentNullOrEmpty" Value="False" /> - <Condition SourceName="PART_EditableTextBox" Property="IsKeyboardFocused" Value="True" /> - </MultiTrigger.Conditions> - <Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" /> - <Setter TargetName="Hint" Property="HintOpacity" Value="1" /> - </MultiTrigger> - <MultiTrigger> - <MultiTrigger.Conditions> - <Condition SourceName="Hint" Property="IsContentNullOrEmpty" Value="False" /> - <Condition Property="IsDropDownOpen" Value="True" /> - </MultiTrigger.Conditions> - <Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" /> - <Setter TargetName="Hint" Property="HintOpacity" Value="1" /> - </MultiTrigger> - <MultiTrigger> - <MultiTrigger.Conditions> - <Condition Property="IsGrouping" Value="true" /> - <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false" /> - </MultiTrigger.Conditions> - <Setter Property="ScrollViewer.CanContentScroll" Value="false" /> - </MultiTrigger> - <Trigger Property="IsKeyboardFocused" Value="true"> - <Setter TargetName="Underline" Property="IsActive" Value="True"/> - </Trigger> - <Trigger Property="Validation.HasError" Value="true"> - <Setter Property="BorderBrush" Value="{DynamicResource ValidationErrorBrush}"/> - <Setter TargetName="Underline" Property="Background" Value="{DynamicResource ValidationErrorBrush}"/> - </Trigger> - <MultiTrigger> - <MultiTrigger.Conditions> - <Condition Property="IsMouseOver" Value="true" /> - <Condition Property="Validation.HasError" Value="true" /> - </MultiTrigger.Conditions> - <Setter Property="BorderBrush" Value="{DynamicResource ValidationErrorBrush}"/> - <Setter TargetName="Underline" Property="Background" Value="{DynamicResource ValidationErrorBrush}"/> - </MultiTrigger> - <MultiTrigger> - <MultiTrigger.Conditions> - <Condition Property="IsMouseOver" Value="true" /> - <Condition Property="Validation.HasError" Value="false" /> - </MultiTrigger.Conditions> - <Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}"/> - <Setter TargetName="Underline" Property="Background" Value="{DynamicResource PrimaryHueMidBrush}"/> - </MultiTrigger> - </ControlTemplate.Triggers> + + </Border> </ControlTemplate> </Setter.Value> </Setter> diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/SearchComboBox.cs b/Software/Visual_Studio/Tango.SharedUI/Controls/SearchComboBox.cs index 8fc6483e9..96e377b7c 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Controls/SearchComboBox.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Controls/SearchComboBox.cs @@ -15,16 +15,12 @@ using System.Windows.Threading; namespace Tango.SharedUI.Controls { - [TemplatePart(Name = SearchComboBox.PartEditor, Type = typeof(System.Windows.Controls.TextBox))] public class SearchComboBox : ComboBox { - public const string PartEditor = "Search"; - private TextBox _textBox; private ListBox _listBox; private ICollectionView _view; - #region Properties public bool IsOpened { get { return (bool)GetValue(IsOpenedProperty); } @@ -57,40 +53,20 @@ namespace Tango.SharedUI.Controls public static readonly DependencyProperty ListItemsSourceProperty = DependencyProperty.Register("ListItemsSource", typeof(IEnumerable), typeof(SearchComboBox), new PropertyMetadata(null)); - #endregion - #region Constructors - - static SearchComboBox() - { - DefaultStyleKeyProperty.OverrideMetadata(typeof(SearchComboBox), new FrameworkPropertyMetadata(typeof(SearchComboBox))); - } - #endregion //Constructors - #region Initialization - - /// <summary> - /// When overridden in a derived class, is invoked whenever application code or internal processes call <see cref="M:System.Windows.FrameworkElement.ApplyTemplate" />. - /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); - - _textBox = GetTemplateChild(PartEditor) as TextBox; - if(_textBox != null) - { - _textBox.PreviewKeyDown += _textBox_KeyDown; - } + _textBox = GetTemplateChild("txt") as TextBox; _listBox = GetTemplateChild("list") as ListBox; - if(_listBox != null) - { - _listBox.PreviewKeyDown += _listBox_PreviewKeyDown; - _listBox.PreviewMouseLeftButtonUp += _listBox_PreviewMouseLeftButtonUp; - } - } + _textBox.PreviewKeyDown += _textBox_KeyDown; + _listBox.PreviewKeyDown += _listBox_PreviewKeyDown; + + _listBox.PreviewMouseLeftButtonUp += _listBox_PreviewMouseLeftButtonUp; - #endregion + KeyboardNavigation.SetDirectionalNavigation(this, KeyboardNavigationMode.Once); + } - #region Event Handlers private void _listBox_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Return) @@ -104,9 +80,24 @@ namespace Tango.SharedUI.Controls { if (e.Key == Key.Down) { - _listBox.SelectedIndex = 0; - _listBox.Focus(); + if (!String.IsNullOrWhiteSpace(SearchFilter)) + { + _listBox.SelectedIndex = 0; + } + Keyboard.Focus(_listBox); + + if (_listBox.SelectedIndex != -1) + { + var container = _listBox.ItemContainerGenerator.ContainerFromIndex(_listBox.SelectedIndex) as UIElement; + if (container != null) + { + container.Focus(); + Keyboard.Focus(container); + } + } + e.Handled = true; + _listBox.ScrollIntoView(_listBox.SelectedItem); } } @@ -123,23 +114,15 @@ namespace Tango.SharedUI.Controls { if (IsOpened) { + SearchFilter = String.Empty; _listBox.SelectedItem = SelectedItem; - SearchFilter = ""; + _listBox.ScrollIntoView(_listBox.SelectedItem); await Task.Delay(100); _textBox.Focus(); - Keyboard.Focus(_textBox); } } - private void OnFilterChanged() - { - _view?.Refresh(); - } - - #endregion - #region Override - protected override void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue) { base.OnItemsSourceChanged(oldValue, newValue); @@ -155,9 +138,7 @@ namespace Tango.SharedUI.Controls if (x != null) { - var prop = x.GetType().GetProperty(SearchProperty); - - // var prop = x.GetType().GetProperty(SearchProperty, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly); + var prop = x.GetType().GetProperty(SearchProperty, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); if (prop != null) { String propValue = prop.GetValue(x).ToString(); @@ -170,12 +151,43 @@ namespace Tango.SharedUI.Controls } } - protected override void OnSelectionChanged(SelectionChangedEventArgs e) + private void OnFilterChanged() + { + _view?.Refresh(); + + if (_listBox != null && _listBox.Items.Count > 0) + { + _listBox.ScrollIntoView(_listBox.Items[0]); + } + } + + protected override void OnPreviewKeyDown(KeyEventArgs e) { - base.OnSelectionChanged(e); + //base.OnPreviewKeyDown(e); + e.Handled = false; } - #endregion - + protected override void OnPreviewKeyUp(KeyEventArgs e) + { + //base.OnPreviewKeyUp(e); + e.Handled = false; + } + + protected override void OnKeyDown(KeyEventArgs e) + { + //base.OnKeyDown(e); + e.Handled = false; + } + + protected override void OnKeyUp(KeyEventArgs e) + { + //base.OnKeyUp(e); + e.Handled = false; + } + + static SearchComboBox() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(SearchComboBox), new FrameworkPropertyMetadata(typeof(SearchComboBox))); + } } } |
