diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-04-07 15:02:30 +0200 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-04-07 15:02:30 +0200 |
| commit | 427961e3fe8169d517630a8bc8445a853fe86040 (patch) | |
| tree | ba4022957259f9781ce8b15de198044f0a1f572c /Software/Visual_Studio/Tango.SharedUI | |
| parent | 7f58e70e72f9704884f38d4d7c1809e8b0bbc10a (diff) | |
| download | Tango-427961e3fe8169d517630a8bc8445a853fe86040.tar.gz Tango-427961e3fe8169d517630a8bc8445a853fe86040.zip | |
MultiSelectCombobox control. Added icons, styles,.
Diffstat (limited to 'Software/Visual_Studio/Tango.SharedUI')
| -rw-r--r-- | Software/Visual_Studio/Tango.SharedUI/Controls/MultiSelectComboBox.cs | 39 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.SharedUI/Images/PinClose_Black.png | bin | 0 -> 1230 bytes | |||
| -rw-r--r-- | Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj | 3 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.SharedUI/Themes/Generic.xaml | 39 |
4 files changed, 58 insertions, 23 deletions
diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/MultiSelectComboBox.cs b/Software/Visual_Studio/Tango.SharedUI/Controls/MultiSelectComboBox.cs index dcbc35f60..153b36804 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Controls/MultiSelectComboBox.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Controls/MultiSelectComboBox.cs @@ -18,6 +18,7 @@ using Tango.Core.Commands; using System.ComponentModel; using System.Windows.Controls.Primitives; using System.Windows.Threading; +using System.Diagnostics; namespace Tango.SharedUI.Controls { @@ -54,9 +55,9 @@ namespace Tango.SharedUI.Controls public MultiSelectComboBox() : base() { SelectedItemsList = new ObservableCollection<object>(); - RemoveAllCommand = new RelayCommand(RemoveAllSelectedItems, () => SelectedItemsList != null && SelectedItemsList.Count > 1); - RemoveItemCommand = new RelayCommand<MultiSelectComboBoxItem>((item) => SelectedItemsList.Remove(item), () => SelectedItemsList != null); - AddItemCommand = new RelayCommand<string>((item) => SelectedItemsList.Insert(SelectedItemsList.Count-1, new MultiSelectComboBoxItem(item))); + RemoveAllCommand = new RelayCommand(RemoveAllSelectedItems, CanRemoveAllSelectedItems); + RemoveItemCommand = new RelayCommand<MultiSelectComboBoxItem>(RemoveSelectedItem); + AddItemCommand = new RelayCommand<string>(AddSelectedItem); SearchText = new MultiSelectComboBoxSearchItem(); Loaded += MultiSelectComboBox_Loaded; _isLoaded = false; @@ -272,10 +273,10 @@ namespace Tango.SharedUI.Controls /// <summary> /// The remove all command property for clear SelectedItemsList /// </summary> - public static DependencyProperty RemoveAllCommandProperty = DependencyProperty.Register("RemoveAllCommand", typeof(ICommand), typeof(MultiSelectComboBox)); - public ICommand RemoveAllCommand + public static DependencyProperty RemoveAllCommandProperty = DependencyProperty.Register("RemoveAllCommand", typeof(RelayCommand), typeof(MultiSelectComboBox)); + public RelayCommand RemoveAllCommand { - get { return (ICommand)GetValue(RemoveAllCommandProperty); } + get { return (RelayCommand)GetValue(RemoveAllCommandProperty); } private set { SetValue(RemoveAllCommandProperty, value); } } @@ -300,6 +301,27 @@ namespace Tango.SharedUI.Controls } /// <summary> + /// Removes the selected item. + /// </summary> + /// <param name="item">The item.</param> + private void RemoveSelectedItem(IMultiSelectComboBoxItem item) + { + SelectedItemsList.Remove(item); + RemoveAllCommand.RaiseCanExecuteChanged(); + } + + /// <summary> + /// Adds the selected item. + /// </summary> + /// <param name="item">The item.</param> + private void AddSelectedItem(string item) + { + if (SelectedItemsList.Any(x => (x as IMultiSelectComboBoxItem).Text == item)) + return; + SelectedItemsList.Insert(SelectedItemsList.Count - 1, new MultiSelectComboBoxItem(item)); + RemoveAllCommand.RaiseCanExecuteChanged(); + } + /// <summary> /// Removes all selected items. /// </summary> private void RemoveAllSelectedItems() @@ -309,6 +331,11 @@ namespace Tango.SharedUI.Controls { SelectedItemsList.RemoveAt(index--); } + RemoveAllCommand.RaiseCanExecuteChanged(); + } + private bool CanRemoveAllSelectedItems() + { + return (SelectedItemsList != null && SelectedItemsList.Count > 1); } #endregion diff --git a/Software/Visual_Studio/Tango.SharedUI/Images/PinClose_Black.png b/Software/Visual_Studio/Tango.SharedUI/Images/PinClose_Black.png Binary files differnew file mode 100644 index 000000000..abf709cb5 --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Images/PinClose_Black.png diff --git a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj index f02df13be..3b2512355 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj +++ b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj @@ -253,6 +253,9 @@ <Name>Tango.Scripting</Name> </ProjectReference> </ItemGroup> + <ItemGroup> + <Resource Include="Images\PinClose_Black.png" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> diff --git a/Software/Visual_Studio/Tango.SharedUI/Themes/Generic.xaml b/Software/Visual_Studio/Tango.SharedUI/Themes/Generic.xaml index 3678c3325..ec9e86d07 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Themes/Generic.xaml +++ b/Software/Visual_Studio/Tango.SharedUI/Themes/Generic.xaml @@ -12,7 +12,7 @@ <Setter.Value> <ControlTemplate TargetType="{x:Type local:MultiSelectComboBox}"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" - BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3" > + BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> @@ -30,25 +30,25 @@ <ScrollViewer VerticalScrollBarVisibility="Auto" > <ScrollViewer.Resources> <Style TargetType="ScrollBar"> - <Setter Property="Width" Value="9"/> - <Setter Property="MinWidth" Value="9" /> + <Setter Property="Width" Value="6"/> + <Setter Property="MinWidth" Value="6" /> </Style> </ScrollViewer.Resources> <ItemsControl x:Name="SelectedItemsControl" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=local:MultiSelectComboBox}, Path=SelectedItemsList}" - ItemTemplateSelector="{StaticResource MultiSelectComboBoxTemplateSelector}" MinHeight="80" VerticalAlignment="Stretch"> + ItemTemplateSelector="{StaticResource MultiSelectComboBoxTemplateSelector}" MinHeight="20" VerticalAlignment="Stretch"> <ItemsControl.Resources> - <DataTemplate x:Key="CheckItem"> - <Button Margin="4,2" Height="25" Width="Auto" Background="Transparent" BorderThickness="0.5" BorderBrush="{Binding RelativeSource={RelativeSource AncestorType=local:MultiSelectComboBox}, Path=BorderBrush}" + <DataTemplate x:Key="CheckItem"> + <Button Margin="2" Height="25" Width="Auto" Background="Transparent" BorderThickness="0.5" BorderBrush="{Binding RelativeSource={RelativeSource AncestorType=local:MultiSelectComboBox}, Path=BorderBrush}" Command="{Binding RelativeSource={RelativeSource AncestorType=local:MultiSelectComboBox}, Path=RemoveItemCommand}" CommandParameter="{Binding}"> - <StackPanel Orientation="Horizontal"> - <TextBlock Text="{Binding Text}" VerticalAlignment="Center" /> - <fa:ImageAwesome Icon="Close" Width="12" Margin="2" VerticalAlignment="Center" HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5"/> - </StackPanel> - </Button> - </DataTemplate> - <DataTemplate x:Key="SearchItem"> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding Text}" VerticalAlignment="Center" Margin="2"/> + <Image Source="/Tango.SharedUI;component/Images/PinClose_Black.png" Width="10" Margin="2 2 2 0" VerticalAlignment="Center" HorizontalAlignment="Right" /> + </StackPanel> + </Button> + </DataTemplate> + <DataTemplate x:Key="SearchItem"> <TextBox x:Name="Edit_PART" Height="25" MinWidth="20" HorizontalContentAlignment="Stretch" VerticalAlignment="Top" BorderBrush="Transparent" VerticalContentAlignment="Center" BorderThickness="0" - Text="{Binding Text}" Margin="2"/> + Text="{Binding Text}" Margin="2" Background="{Binding Path=BorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"/> </DataTemplate> </ItemsControl.Resources> <ItemsControl.Template> @@ -67,9 +67,14 @@ </ControlTemplate> </ToggleButton.Template> </ToggleButton> - <Button Grid.Column=" 1" BorderBrush="Transparent" Opacity="0.05" VerticalContentAlignment="Top" Command="{Binding RelativeSource={RelativeSource AncestorType=local:MultiSelectComboBox}, Path=RemoveAllCommand}"> - <fa:ImageAwesome Icon="Times" Width="12" Foreground="{TemplateBinding Foreground}" Margin="10" VerticalAlignment="Top"> - </fa:ImageAwesome> + <Button Grid.Column=" 1" BorderBrush="Transparent" Opacity="0.2" VerticalContentAlignment="Top" Command="{Binding RelativeSource={RelativeSource AncestorType=local:MultiSelectComboBox}, Path=RemoveAllCommand}" Width="20"> + <Grid VerticalAlignment="Top"> + <Grid.RowDefinitions> + <RowDefinition Height="15" /> + <RowDefinition Height="*" /> + </Grid.RowDefinitions> + <Image Grid.Row="0" Source="/Tango.SharedUI;component/Images/PinClose_Black.png" MinWidth="10" Margin="0" VerticalAlignment="Top" HorizontalAlignment="Stretch"/> + </Grid> <Button.Style> <Style TargetType="Button"> <Setter Property="Template"> |
