diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-02-26 18:43:43 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-02-26 18:43:43 +0200 |
| commit | 8e5ab17ced647a8c9fbba764c6fa0c06d56269c9 (patch) | |
| tree | 4d958c4775ac237f5d67803192aa530a80d978b7 /Software/Visual_Studio/Tango.SharedUI | |
| parent | afb6bbb2123932b3562e1af993eb847d8147bf58 (diff) | |
| parent | 228dca3384369f23d6dcad6a696cf491ab9d8840 (diff) | |
| download | Tango-8e5ab17ced647a8c9fbba764c6fa0c06d56269c9.tar.gz Tango-8e5ab17ced647a8c9fbba764c6fa0c06d56269c9.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Tango.SharedUI')
4 files changed, 315 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/MultiSelectComboBox.cs b/Software/Visual_Studio/Tango.SharedUI/Controls/MultiSelectComboBox.cs new file mode 100644 index 000000000..66eaa4e14 --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Controls/MultiSelectComboBox.cs @@ -0,0 +1,180 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Core.Commands; +using System.ComponentModel; + +namespace Tango.SharedUI.Controls +{ + public class MultiSelectComboBox : Control + { + static MultiSelectComboBox() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(MultiSelectComboBox), new FrameworkPropertyMetadata(typeof(MultiSelectComboBox))); + + } + + public MultiSelectComboBox() : base() + { + RemoveAllCommand = new RelayCommand((() => SelectedItemsList.Clear()), () => SelectedItemsList != null && SelectedItemsList.Count > 0); + RemoveItemCommand = new RelayCommand<string>((item) => SelectedItemsList.Remove(item), () => SelectedItemsList != null); + AddItemCommand = new RelayCommand<string>((item) => SelectedItemsList.Add(item)); + SearchText = ""; + } + + #region Properties + + public ObservableCollection<string> SelectedItemsList + { + get { return (ObservableCollection<string>)GetValue(SelectedItemsListProperty); } + set { SetValue(SelectedItemsListProperty, value); } + } + + public static readonly DependencyProperty SelectedItemsListProperty = + DependencyProperty.Register("SelectedItemsList", typeof(ObservableCollection<string>), typeof(MultiSelectComboBox), new PropertyMetadata(default(ObservableCollection<string>))); + + + public ListCollectionView SearchItemsList + { + get { return (ListCollectionView)GetValue(SearchItemsListProperty); } + set { SetValue(SearchItemsListProperty, value); } + } + /// <summary> + /// The search items list property for popup items list + /// </summary> + public static readonly DependencyProperty SearchItemsListProperty = + DependencyProperty.Register("SearchItemsList", typeof(ListCollectionView), typeof(MultiSelectComboBox), new PropertyMetadata(default(ObservableCollection<string>))); + + public ObservableCollection<string> Items + { + get { return (ObservableCollection<string>)GetValue(ItemsProperty); } + set { SetValue(ItemsProperty, value); } + } + + public static readonly DependencyProperty ItemsProperty = + DependencyProperty.Register("Items", typeof(ObservableCollection<string>), typeof(MultiSelectComboBox), new PropertyMetadata(default(ObservableCollection<string>))); + + + + public bool IsToggleChecked + { + get { return (bool)GetValue(IsToggleCheckedProperty); } + set { SetValue(IsToggleCheckedProperty, value); } + } + public static readonly DependencyProperty IsToggleCheckedProperty = + DependencyProperty.Register("IsToggleChecked", typeof(bool), typeof(MultiSelectComboBox), new PropertyMetadata(false)); + + + + private string _searchText; + /// <summary> + /// Gets or sets the search text of TextBox. + /// </summary> + public string SearchText + { + get { return _searchText; } + set {_searchText = value; + RaisePropertyChanged("SearchText"); + OnTextChanged(); + } + } + + void OnTextChanged() + { + if(SearchItemsList != null) + { + if (String.IsNullOrEmpty(SearchText)) + SearchItemsList.Filter = null; + else + SearchItemsList.Filter = new Predicate<object>(o => ((string)o == SearchText)); + } + } + /// <summary> + /// Occurs when a property has changed. + /// </summary> + public event PropertyChangedEventHandler PropertyChanged; + + /// <summary> + /// Raises the property changed event. + /// </summary> + /// <param name="propName">Name of the property.</param> + protected virtual void RaisePropertyChanged(String propName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName)); + } + + + #endregion + + /// <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(); + if (SelectedItemsList == null) + SelectedItemsList = new ObservableCollection<string>(); + SearchItemsList = new ListCollectionView(this.Items); + + //ItemsControl iControl = FindName("asd") as ItemsControl; + //iControl.ItemContainerGenerator.ItemsChanged += ItemContainerGenerator_ItemsChanged; + //iControl.ItemContainerGenerator.ContainerFromItem(null); + + //for (int i = 0; i < iControl.Items.Count; i++) + //{ + // FrameworkElement a = iControl.ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement; + //} + } + + private void ItemContainerGenerator_ItemsChanged(object sender, System.Windows.Controls.Primitives.ItemsChangedEventArgs e) + { + + } + + #region Commands + /// <summary> + /// The remove all command property for clear SelectedItemsList + /// </summary> + public static DependencyProperty RemoveAllCommandProperty = DependencyProperty.Register("RemoveAllCommand", typeof(ICommand), typeof(MultiSelectComboBox)); + public ICommand RemoveAllCommand + { + get { return (ICommand)GetValue(RemoveAllCommandProperty); } + private set { SetValue(RemoveAllCommandProperty, value); } + } + + /// <summary> + /// The remove item from SelectedItemsList command property + /// </summary> + public static DependencyProperty RemoveItemCommandProperty = DependencyProperty.Register("RemoveItemCommand", typeof(RelayCommand<string>), typeof(MultiSelectComboBox)); + public RelayCommand<string> RemoveItemCommand + { + get { return (RelayCommand<string>)GetValue(RemoveItemCommandProperty); } + private set { SetValue(RemoveItemCommandProperty, value); } + } + + + public static DependencyProperty AddItemCommandProperty = DependencyProperty.Register("AddItemCommand", typeof(RelayCommand<string>), typeof(MultiSelectComboBox)); + public RelayCommand<string> AddItemCommand + { + get { return (RelayCommand<string>)GetValue(AddItemCommandProperty); } + private set { SetValue(AddItemCommandProperty, value); } + } + #endregion + + + + } +} diff --git a/Software/Visual_Studio/Tango.SharedUI/Converters/TimeSpanToTwoDigitsTimeConverter.cs b/Software/Visual_Studio/Tango.SharedUI/Converters/TimeSpanToTwoDigitsTimeConverter.cs index fb162d29b..8946020bf 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Converters/TimeSpanToTwoDigitsTimeConverter.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Converters/TimeSpanToTwoDigitsTimeConverter.cs @@ -12,6 +12,9 @@ namespace Tango.SharedUI.Converters { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + if (value == null) + return ""; + TimeSpan time = (TimeSpan)value; if (time.TotalHours > 1) diff --git a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj index 092afd777..2170b6d58 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj +++ b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj @@ -74,6 +74,7 @@ <Compile Include="Controls\HiveControl.xaml.cs"> <DependentUpon>HiveControl.xaml</DependentUpon> </Compile> + <Compile Include="Controls\MultiSelectComboBox.cs" /> <Compile Include="Controls\MultiSelectDataGrid.cs" /> <Compile Include="Controls\MultiSelectListBox.cs" /> <Compile Include="Controls\MultiTransitionControl.xaml.cs"> @@ -212,6 +213,10 @@ <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </Page> + <Page Include="Themes\Generic.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> </ItemGroup> <ItemGroup> <Resource Include="Images\pubclass.gif" /> diff --git a/Software/Visual_Studio/Tango.SharedUI/Themes/Generic.xaml b/Software/Visual_Studio/Tango.SharedUI/Themes/Generic.xaml new file mode 100644 index 000000000..85e9dbb8b --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Themes/Generic.xaml @@ -0,0 +1,127 @@ +<ResourceDictionary + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:fa="http://schemas.fontawesome.io/icons/" + xmlns:local="clr-namespace:Tango.SharedUI.Controls"> + + + + <Style TargetType="{x:Type local:MultiSelectComboBox}"> + <Setter Property="Background" Value="Transparent"></Setter> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type local:MultiSelectComboBox}"> + <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3" > + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*" /> + <ColumnDefinition Width="Auto"/> + </Grid.ColumnDefinitions> + <ToggleButton x:Name="MultiSelToggleButton" Grid.Column="0" MinHeight="40" Height="Auto" + VerticalAlignment="Center" + HorizontalAlignment="Stretch" Margin="4,0,0,0" SnapsToDevicePixels="True" + Foreground="{TemplateBinding Foreground}" BorderBrush="{TemplateBinding BorderBrush}" + IsChecked="{Binding RelativeSource={RelativeSource AncestorType=local:MultiSelectComboBox}, Path=IsToggleChecked,Mode=TwoWay}"> + <ToggleButton.Template> + <ControlTemplate TargetType="ToggleButton"> + <Grid > + <WrapPanel> + <ItemsControl x:Name="SelectedItems" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=local:MultiSelectComboBox}, Path=SelectedItemsList}"> + <ItemsControl.Template> + <ControlTemplate TargetType="{x:Type ItemsControl}"> + <ItemsPresenter HorizontalAlignment="Stretch" /> + </ControlTemplate> + </ItemsControl.Template> + <ItemsControl.ItemsPanel> + <ItemsPanelTemplate> + <WrapPanel IsItemsHost="True" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Left"/> + </ItemsPanelTemplate> + </ItemsControl.ItemsPanel> + <ItemsControl.ItemTemplate> + <DataTemplate> + <Button Margin="4,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}" VerticalAlignment="Center" /> + <fa:ImageAwesome Icon="Close" Width="12" Margin="2" VerticalAlignment="Center" HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5"/> + </StackPanel> + </Button> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + <TextBox x:Name="Edit_PART" Height="25" VerticalAlignment="Top" BorderBrush="Transparent" VerticalContentAlignment="Center" BorderThickness="0" + Text="{Binding RelativeSource={RelativeSource AncestorType=local:MultiSelectComboBox},Path=SearchText, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Margin="2"></TextBox> + </WrapPanel> + </Grid> + </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.Style> + <Style TargetType="Button"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type Button}"> + <Border Background="{TemplateBinding Background}"> + <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + <Style.Triggers> + <Trigger Property="IsMouseOver" Value="True"> + <Setter Property="Background" Value="Transparent" /> + <Setter Property="BorderBrush" Value="Transparent"/> + </Trigger> + <Trigger Property="IsMouseOver" Value="False"> + <Setter Property="Background" Value="Transparent" /> + <Setter Property="BorderBrush" Value="Transparent"/> + </Trigger> + <EventTrigger RoutedEvent="Control.MouseEnter"> + <BeginStoryboard> + <Storyboard > + <DoubleAnimation Duration="0:0:1" To="1" Storyboard.TargetProperty="Opacity"/> + </Storyboard> + </BeginStoryboard> + </EventTrigger> + <EventTrigger RoutedEvent="Control.MouseLeave"> + <BeginStoryboard> + <Storyboard > + <DoubleAnimation Duration="0:0:1" To="0.05" Storyboard.TargetProperty="Opacity"/> + </Storyboard> + </BeginStoryboard> + </EventTrigger> + </Style.Triggers> + </Style> + </Button.Style> + </Button> + <Popup x:Name="MultiSel_Popup" Tag="{Binding RelativeSource={RelativeSource AncestorType=local:MultiSelectComboBox}}" MinHeight="25" MaxHeight="600" HorizontalOffset="0" MinWidth="{TemplateBinding ActualWidth}" MaxWidth="800" Grid.ColumnSpan="2" + PlacementTarget="{Binding ElementName=MultiSelToggleButton}" Placement="Bottom" AllowsTransparency="True" + IsOpen="{Binding RelativeSource={RelativeSource Self},Path=Tag.IsToggleChecked,Mode=TwoWay}" PopupAnimation="Slide" > + <Border Opacity="1" Background="{TemplateBinding Background}" Padding="3" BorderThickness="1" BorderBrush="Beige"> + <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden"> + <ItemsControl x:Name="PropertyDisplay" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=local:MultiSelectComboBox}, Path=SearchItemsList}"> + <ItemsControl.ItemTemplate> + <DataTemplate> + <Button Margin="4,2" Height="Auto" Width="Auto" Background="Transparent" BorderThickness="0.5" BorderBrush="{Binding RelativeSource={RelativeSource AncestorType=local:MultiSelectComboBox}, Path=BorderBrush}" + Command="{Binding RelativeSource={RelativeSource AncestorType=local:MultiSelectComboBox}, Path=AddItemCommand}" CommandParameter="{Binding}"> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{Binding}" VerticalAlignment="Center" /> + </StackPanel> + </Button> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + </ScrollViewer> + </Border> + </Popup> + </Grid> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> +</ResourceDictionary> |
