More work on Issue #22 - added remove item button to items in the EditableListBoxControl on mouseover.
This commit is contained in:
parent
7d2e20e9e1
commit
d014a93b70
|
@ -172,6 +172,7 @@
|
|||
<DependentUpon>BlockItemControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UserControls\CrossButton.cs" />
|
||||
<Compile Include="UserControls\DesignTime\DesignTimeEditableListBoxControl.cs" />
|
||||
<Compile Include="UserControls\EditableListBoxControl.xaml.cs">
|
||||
<DependentUpon>EditableListBoxControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
using System.Collections.Generic;
|
||||
using GalaSoft.MvvmLight.CommandWpf;
|
||||
|
||||
namespace Filtration.UserControls.DesignTime
|
||||
{
|
||||
internal class DesignTimeEditableListBoxControl : IEditableListBoxControl
|
||||
{
|
||||
public RelayCommand AddItemCommand { get; }
|
||||
public RelayCommand<string> DeleteItemCommand { get; }
|
||||
public IEnumerable<string> AutoCompleteItemsSource { get; set; }
|
||||
ICollection<string> IEditableListBoxControl.ItemsSource { get; set; }
|
||||
|
||||
public string Label
|
||||
{
|
||||
get { return "Base Types"; }
|
||||
set { }
|
||||
}
|
||||
|
||||
public string AddItemText { get; set; }
|
||||
|
||||
public ICollection<string> ItemsSource
|
||||
{
|
||||
get { return new List<string> {"Test Item 1", "Blah", "Another Item"}; }
|
||||
}
|
||||
|
||||
public string SelectedItem { get { return "Blah"; } }
|
||||
}
|
||||
}
|
|
@ -5,10 +5,11 @@
|
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:userControls="clr-namespace:Filtration.UserControls"
|
||||
xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
|
||||
xmlns:designTime="clr-namespace:Filtration.UserControls.DesignTime"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance Type=userControls:EditableListBoxControl}">
|
||||
d:DataContext="{d:DesignInstance Type=designTime:DesignTimeEditableListBoxControl, IsDesignTimeCreatable=True}">
|
||||
|
||||
<Grid VerticalAlignment="Top">
|
||||
<Grid VerticalAlignment="Top" Name="LayoutRoot">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
|
@ -21,8 +22,11 @@
|
|||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
ItemsSource="{Binding ItemsSource}"
|
||||
SelectedItem="{Binding SelectedItem}"
|
||||
BorderThickness="1"
|
||||
Height="120"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
VerticalAlignment="Stretch" SelectionMode="Single" x:Name="ControlListBox" BorderBrush="#CCCCCC">
|
||||
<ListBox.Resources>
|
||||
<Style TargetType="ListBoxItem">
|
||||
|
@ -37,6 +41,31 @@
|
|||
</Style.Resources>
|
||||
</Style>
|
||||
</ListBox.Resources>
|
||||
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid HorizontalAlignment="Stretch">
|
||||
<Grid.Resources>
|
||||
<Style TargetType="Grid" x:Key="MouseoverStyle">
|
||||
<Setter Property="Visibility" Value="Hidden" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsMouseOver}" Value="True">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Grid.Resources>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding}" ToolTip="{Binding}" />
|
||||
<Grid Grid.Column="1" Style="{StaticResource MouseoverStyle}">
|
||||
<userControls:CrossButton Height="12" Command="{Binding ElementName=LayoutRoot, Path=DataContext.DeleteItemCommand}" CommandParameter="{Binding}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
<ListBox.InputBindings>
|
||||
<KeyBinding Key="Delete" Command="{Binding Path=DeleteItemCommand}" CommandParameter="{Binding ElementName=ControlListBox, Path=SelectedValue}" />
|
||||
</ListBox.InputBindings>
|
||||
|
|
|
@ -2,14 +2,22 @@
|
|||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Filtration.Annotations;
|
||||
using GalaSoft.MvvmLight.CommandWpf;
|
||||
|
||||
namespace Filtration.UserControls
|
||||
{
|
||||
public partial class EditableListBoxControl : INotifyPropertyChanged
|
||||
public interface IEditableListBoxControl
|
||||
{
|
||||
RelayCommand AddItemCommand { get; }
|
||||
RelayCommand<string> DeleteItemCommand { get; }
|
||||
IEnumerable<string> AutoCompleteItemsSource { get; set; }
|
||||
ICollection<string> ItemsSource { get; set; }
|
||||
string AddItemText { get; set; }
|
||||
}
|
||||
|
||||
public partial class EditableListBoxControl : INotifyPropertyChanged, IEditableListBoxControl
|
||||
{
|
||||
private string _addItemText;
|
||||
|
||||
|
@ -23,8 +31,8 @@ namespace Filtration.UserControls
|
|||
DeleteItemCommand = new RelayCommand<string>(OnDeleteItemCommand);
|
||||
}
|
||||
|
||||
public RelayCommand AddItemCommand { get; private set; }
|
||||
public RelayCommand<string> DeleteItemCommand { get; private set; }
|
||||
public RelayCommand AddItemCommand { get; }
|
||||
public RelayCommand<string> DeleteItemCommand { get; }
|
||||
|
||||
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register(
|
||||
"ItemsSource",
|
||||
|
@ -33,13 +41,6 @@ namespace Filtration.UserControls
|
|||
new FrameworkPropertyMetadata(OnItemsSourcePropertyChanged)
|
||||
);
|
||||
|
||||
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
|
||||
"Label",
|
||||
typeof (string),
|
||||
typeof (EditableListBoxControl),
|
||||
new FrameworkPropertyMetadata()
|
||||
);
|
||||
|
||||
public static readonly DependencyProperty AutoCompleteItemsSourceProperty = DependencyProperty.Register(
|
||||
"AutoCompleteItemsSource",
|
||||
typeof (IEnumerable<string>),
|
||||
|
@ -59,12 +60,6 @@ namespace Filtration.UserControls
|
|||
set { SetValue(ItemsSourceProperty, value); }
|
||||
}
|
||||
|
||||
public string Label
|
||||
{
|
||||
get { return (string)GetValue(LabelProperty); }
|
||||
set { SetValue(LabelProperty, value); }
|
||||
}
|
||||
|
||||
public string AddItemText
|
||||
{
|
||||
get { return _addItemText; }
|
||||
|
@ -100,6 +95,14 @@ namespace Filtration.UserControls
|
|||
control?.OnPropertyChanged(nameof(ItemsSource));
|
||||
}
|
||||
|
||||
private void AutoCompleteBox_OnPreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
AddItemCommand.Execute(null);
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
|
@ -108,13 +111,5 @@ namespace Filtration.UserControls
|
|||
var handler = PropertyChanged;
|
||||
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
private void AutoCompleteBox_OnPreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
AddItemCommand.Execute(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue