Refactored ItemFilterBlockView to use new usercontrol instead of datatemplate spam

This commit is contained in:
Ben 2015-07-04 21:12:47 +01:00
parent d586492de8
commit da3759cd76
7 changed files with 207 additions and 119 deletions

View File

@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using Filtration.ObjectModel.BlockItemBaseTypes;
namespace Filtration.Converters
{
public class BlockItemToRemoveEnabledVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var actionBlock = value as ActionBlockItem;
return actionBlock != null ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -137,6 +137,7 @@
<Compile Include="Converters\BooleanToBlockActionInverseConverter.cs" />
<Compile Include="Converters\BooleanToBlockActionConverter.cs" />
<Compile Include="Converters\BooleanVisibilityConverterCopy.cs" />
<Compile Include="Converters\BlockItemToRemoveEnabledVisibilityConverter.cs" />
<Compile Include="Converters\ColorToSolidColorBrushConverter.cs" />
<Compile Include="Converters\HashSignRemovalConverter.cs" />
<Compile Include="Converters\ItemRarityConverter.cs" />
@ -158,6 +159,9 @@
<Compile Include="Translators\ItemFilterScriptTranslator.cs" />
<Compile Include="Translators\ThemeComponentListBuilder.cs" />
<Compile Include="UserControls\AutoScrollingListBox.cs" />
<Compile Include="UserControls\BlockItemControl.xaml.cs">
<DependentUpon>BlockItemControl.xaml</DependentUpon>
</Compile>
<Compile Include="UserControls\CrossButton.cs" />
<Compile Include="UserControls\EditableListBoxControl.xaml.cs">
<DependentUpon>EditableListBoxControl.xaml</DependentUpon>
@ -192,6 +196,10 @@
<Compile Include="Views\SettingsPageView.xaml.cs">
<DependentUpon>SettingsPageView.xaml</DependentUpon>
</Compile>
<Page Include="UserControls\BlockItemControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Styles\ListBoxItem.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

View File

@ -0,0 +1,88 @@
<UserControl x:Class="Filtration.UserControls.BlockItemControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:userControls="clr-namespace:Filtration.UserControls"
xmlns:blockItemBaseTypes="clr-namespace:Filtration.ObjectModel.BlockItemBaseTypes;assembly=Filtration.ObjectModel"
xmlns:blockItemTypes="clr-namespace:Filtration.ObjectModel.BlockItemTypes;assembly=Filtration.ObjectModel"
xmlns:extensions="clr-namespace:Filtration.Extensions"
xmlns:enums="clr-namespace:Filtration.ObjectModel.Enums;assembly=Filtration.ObjectModel"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=userControls:BlockItemControl}"
d:DesignHeight="200" d:DesignWidth="150">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<Style TargetType="{x:Type Border}" x:Key="BlockItemBorder">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="CornerRadius" Value="3" />
<Setter Property="Margin" Value="0,0,5,5" />
</Style>
</ResourceDictionary>
<ResourceDictionary Source="../Views/SharedResourcesDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Border Style="{StaticResource BlockItemBorder}" Width="142">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Grid.Row="0" Background="PowderBlue" CornerRadius="3,3,0,0">
<Grid Margin="3,0,3,0">
<TextBlock Text="{Binding BlockItem.DisplayHeading}" Grid.Row="0" VerticalAlignment="Center" Foreground="Navy" />
<userControls:CrossButton Grid.Row="0" Height="12" HorizontalAlignment="Right" VerticalAlignment="Center" Command="{Binding RemoveItemCommand}" CommandParameter="{Binding BlockItem}" Visibility="{Binding RemoveEnabled}"/>
</Grid>
</Border>
<ContentControl Grid.Row="1" Content="{Binding BlockItem}">
<ContentControl.Resources>
<!-- Action Template -->
<DataTemplate DataType="{x:Type blockItemBaseTypes:ActionBlockItem}">
<WrapPanel VerticalAlignment="Center" Margin="5,5,5,5">
<RadioButton IsChecked="{Binding Action, Converter={StaticResource BooleanToBlockActionConverter}}" Margin="0,0,10,0">Show</RadioButton>
<RadioButton IsChecked="{Binding Action, Converter={StaticResource BooleanToBlockActionInverseConverter}}">Hide</RadioButton>
</WrapPanel>
</DataTemplate>
<!-- NumericFilterPredicate Template -->
<DataTemplate DataType="{x:Type blockItemBaseTypes:NumericFilterPredicateBlockItem}">
<userControls:NumericFilterPredicateControl Margin="5,5,5,5" NumericFilterPredicate="{Binding FilterPredicate}" Minimum="{Binding Minimum, Mode=OneTime}" Maximum="{Binding Maximum, Mode=OneTime}" />
</DataTemplate>
<!-- Rarity Template -->
<DataTemplate DataType="{x:Type blockItemTypes:RarityBlockItem}">
<StackPanel Orientation="Horizontal" Margin="5,5,5,5">
<ComboBox ItemsSource="{Binding Source={extensions:Enumeration {x:Type enums:FilterPredicateOperator}}}"
DisplayMemberPath="Description"
SelectedValue="{Binding FilterPredicate.PredicateOperator}"
SelectedValuePath="Value" Width="50" Margin="0,0,6,0" />
<ComboBox ItemsSource="{Binding Source={extensions:Enumeration {x:Type enums:ItemRarity}}}"
DisplayMemberPath="Description"
SelectedValue="{Binding FilterPredicate.PredicateOperand, Converter={StaticResource IntToItemRarityConverter}}"
SelectedValuePath="Value" />
</StackPanel>
</DataTemplate>
<!-- Class Template -->
<DataTemplate DataType="{x:Type blockItemTypes:ClassBlockItem}">
<userControls:EditableListBoxControl Margin="5,5,5,5" ItemsSource="{Binding Items}" AutoCompleteItemsSource="{Binding ElementName=TopLevelGrid, Path=DataContext.AutoCompleteItemClasses}" />
</DataTemplate>
<!-- Base Type Template -->
<DataTemplate DataType="{x:Type blockItemTypes:BaseTypeBlockItem}">
<userControls:EditableListBoxControl Margin="5,5,5,5" ItemsSource="{Binding Items}" AutoCompleteItemsSource="{Binding ElementName=TopLevelGrid, Path=DataContext.AutoCompleteItemBaseTypes}" />
</DataTemplate>
<!-- Socket Groups Template -->
<DataTemplate DataType="{x:Type blockItemTypes:SocketGroupBlockItem}">
<userControls:EditableListBoxControl Margin="5,5,5,5" ItemsSource="{Binding Items}" />
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
</Grid>
</Border>
</UserControl>

View File

@ -0,0 +1,83 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using Filtration.Annotations;
using Filtration.ObjectModel;
using Filtration.ObjectModel.BlockItemBaseTypes;
using GalaSoft.MvvmLight.CommandWpf;
namespace Filtration.UserControls
{
public partial class BlockItemControl : INotifyPropertyChanged
{
public BlockItemControl()
{
InitializeComponent();
// ReSharper disable once PossibleNullReferenceException
(Content as FrameworkElement).DataContext = this;
}
public static readonly DependencyProperty BlockItemProperty = DependencyProperty.Register(
"BlockItem",
typeof(IItemFilterBlockItem),
typeof(BlockItemControl),
new FrameworkPropertyMetadata());
public static readonly DependencyProperty RemoveItemCommandProperty = DependencyProperty.Register(
"RemoveItemCommand",
typeof(RelayCommand<IItemFilterBlockItem>),
typeof(BlockItemControl),
new FrameworkPropertyMetadata());
public static readonly DependencyProperty RemoveEnabledProperty = DependencyProperty.Register(
"RemoveEnabled",
typeof(Visibility),
typeof(BlockItemControl),
new FrameworkPropertyMetadata());
public IItemFilterBlockItem BlockItem
{
get
{
return (IItemFilterBlockItem)GetValue(BlockItemProperty);
}
set
{
SetValue(BlockItemProperty, value);
OnPropertyChanged();
}
}
public RelayCommand<IItemFilterBlockItem> RemoveItemCommand
{
get
{
return (RelayCommand<IItemFilterBlockItem>)GetValue(RemoveItemCommandProperty);
}
set
{
SetValue(RemoveItemCommandProperty, value);
}
}
public Visibility RemoveEnabled
{
get
{
return (Visibility)GetValue(RemoveEnabledProperty);
}
set
{
SetValue(RemoveEnabledProperty, value);
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@ -11,7 +11,6 @@ namespace Filtration.UserControls
InitializeComponent();
// ReSharper disable once PossibleNullReferenceException
(Content as FrameworkElement).DataContext = this;
}
public static readonly DependencyProperty TextColorProperty = DependencyProperty.Register(

View File

@ -7,10 +7,7 @@
xmlns:userControls="clr-namespace:Filtration.UserControls"
xmlns:views="clr-namespace:Filtration.Views"
xmlns:converters="clr-namespace:Filtration.Converters"
xmlns:extensions="clr-namespace:Filtration.Extensions"
xmlns:blockItemBaseTypes="clr-namespace:Filtration.ObjectModel.BlockItemBaseTypes;assembly=Filtration.ObjectModel"
xmlns:blockItemTypes="clr-namespace:Filtration.ObjectModel.BlockItemTypes;assembly=Filtration.ObjectModel"
xmlns:enums="clr-namespace:Filtration.ObjectModel.Enums;assembly=Filtration.ObjectModel"
xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=viewModels:ItemFilterBlockViewModel}"
@ -22,7 +19,6 @@
<ResourceDictionary>
<views:BindingProxy x:Key="proxy" Data="{Binding}" />
<converters:BlockGroupAdvancedFillColorConverter x:Key="BlockGroupAdvancedFillColorConverter" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
@ -210,121 +206,11 @@
</Style.Triggers>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.Resources>
<Style TargetType="{x:Type Border}" x:Key="BlockItemBorder">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="CornerRadius" Value="3" />
<Setter Property="Width" Value="142" />
<Setter Property="Margin" Value="0,0,5,5" />
</Style>
<DataTemplate DataType="{x:Type blockItemBaseTypes:ActionBlockItem}">
<Border Style="{StaticResource BlockItemBorder}">
<WrapPanel VerticalAlignment="Center" Margin="5,5,5,5">
<RadioButton IsChecked="{Binding Action, Converter={StaticResource BooleanToBlockActionConverter}}" Margin="0,0,10,0">Show</RadioButton>
<RadioButton IsChecked="{Binding Action, Converter={StaticResource BooleanToBlockActionInverseConverter}}">Hide</RadioButton>
</WrapPanel>
</Border>
<ItemsControl.ItemTemplate>
<DataTemplate>
<userControls:BlockItemControl BlockItem="{Binding}" RemoveItemCommand="{Binding ElementName=TopLevelGrid, Path=DataContext.RemoveFilterBlockItemCommand}" RemoveEnabled="{Binding Path=., Converter={StaticResource BlockItemToRemoveEnabledVisibilityConverter}}" />
</DataTemplate>
<DataTemplate DataType="{x:Type blockItemBaseTypes:NumericFilterPredicateBlockItem}">
<Border Style="{StaticResource BlockItemBorder}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Border Background="PowderBlue" CornerRadius="3,3,0,0">
<Grid Margin="3,0,3,0">
<TextBlock Text="{Binding DisplayHeading}" Grid.Row="0" VerticalAlignment="Center" Foreground="Navy" />
<userControls:CrossButton Grid.Row="0" Height="12" HorizontalAlignment="Right" VerticalAlignment="Center" Command="{Binding ElementName=TopLevelGrid, Path=DataContext.RemoveFilterBlockItemCommand}" CommandParameter="{Binding}"/>
</Grid>
</Border>
<userControls:NumericFilterPredicateControl Grid.Row="1" Grid.Column="0" Margin="5,5,5,5" NumericFilterPredicate="{Binding FilterPredicate}" Minimum="{Binding Minimum, Mode=OneTime}" Maximum="{Binding Maximum, Mode=OneTime}" />
</Grid>
</Border>
</DataTemplate>
<DataTemplate DataType="{x:Type blockItemTypes:RarityBlockItem}">
<Border Style="{StaticResource BlockItemBorder}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Background="PowderBlue" CornerRadius="3,3,0,0">
<Grid Margin="3,0,3,0">
<TextBlock Text="{Binding DisplayHeading}" Grid.Row="0" VerticalAlignment="Center" Foreground="Navy" />
<userControls:CrossButton Grid.Row="0" Height="12" HorizontalAlignment="Right" VerticalAlignment="Center" Command="{Binding ElementName=TopLevelGrid, Path=DataContext.RemoveFilterBlockItemCommand}" CommandParameter="{Binding}"/>
</Grid>
</Border>
<StackPanel Orientation="Horizontal" Grid.Row="1" Margin="5,5,5,5">
<ComboBox ItemsSource="{Binding Source={extensions:Enumeration {x:Type enums:FilterPredicateOperator}}}"
DisplayMemberPath="Description"
SelectedValue="{Binding FilterPredicate.PredicateOperator}"
SelectedValuePath="Value" Width="50" Margin="0,0,6,0" />
<ComboBox ItemsSource="{Binding Source={extensions:Enumeration {x:Type enums:ItemRarity}}}"
DisplayMemberPath="Description"
SelectedValue="{Binding FilterPredicate.PredicateOperand, Converter={StaticResource IntToItemRarityConverter}}"
SelectedValuePath="Value" />
</StackPanel>
</Grid>
</Border>
</DataTemplate>
<!-- TODO: Sort out these messy duplicated data templates -->
<DataTemplate DataType="{x:Type blockItemTypes:ClassBlockItem}">
<Border Style="{StaticResource BlockItemBorder}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Background="PowderBlue" CornerRadius="3,3,0,0">
<Grid Margin="3,0,3,0">
<TextBlock Text="{Binding DisplayHeading}" Grid.Row="0" VerticalAlignment="Center" Foreground="Navy" />
<userControls:CrossButton Grid.Row="0" Height="12" HorizontalAlignment="Right" VerticalAlignment="Center" Command="{Binding ElementName=TopLevelGrid, Path=DataContext.RemoveFilterBlockItemCommand}" CommandParameter="{Binding}"/>
</Grid>
</Border>
<userControls:EditableListBoxControl Grid.Row="1" Grid.Column="0" Margin="5,5,5,5" ItemsSource="{Binding Items}" AutoCompleteItemsSource="{Binding ElementName=TopLevelGrid, Path=DataContext.AutoCompleteItemClasses}" />
</Grid>
</Border>
</DataTemplate>
<DataTemplate DataType="{x:Type blockItemTypes:BaseTypeBlockItem}">
<Border Style="{StaticResource BlockItemBorder}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Background="PowderBlue" CornerRadius="3,3,0,0">
<Grid Margin="3,0,3,0">
<TextBlock Text="{Binding DisplayHeading}" Grid.Row="0" VerticalAlignment="Center" Foreground="Navy" />
<userControls:CrossButton Grid.Row="0" Height="12" HorizontalAlignment="Right" VerticalAlignment="Center" Command="{Binding ElementName=TopLevelGrid, Path=DataContext.RemoveFilterBlockItemCommand}" CommandParameter="{Binding}"/>
</Grid>
</Border>
<userControls:EditableListBoxControl Grid.Row="1" Grid.Column="0" Margin="5,5,5,5" ItemsSource="{Binding Items}" AutoCompleteItemsSource="{Binding ElementName=TopLevelGrid, Path=DataContext.AutoCompleteItemBaseTypes}" />
</Grid>
</Border>
</DataTemplate>
<DataTemplate DataType="{x:Type blockItemTypes:SocketGroupBlockItem}">
<Border Style="{StaticResource BlockItemBorder}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Background="PowderBlue" CornerRadius="3,3,0,0">
<Grid Margin="3,0,3,0">
<TextBlock Text="{Binding DisplayHeading}" Grid.Row="0" VerticalAlignment="Center" Foreground="Navy" />
<userControls:CrossButton Grid.Row="0" Height="12" HorizontalAlignment="Right" VerticalAlignment="Center" Command="{Binding ElementName=TopLevelGrid, Path=DataContext.RemoveFilterBlockItemCommand}" CommandParameter="{Binding}"/>
</Grid>
</Border>
<userControls:EditableListBoxControl Grid.Row="1" Grid.Column="0" Margin="5,5,5,5" ItemsSource="{Binding Items}" />
</Grid>
</Border>
</DataTemplate>
<DataTemplate DataType="{x:Type blockItemBaseTypes:ColorBlockItem}" />
<DataTemplate DataType="{x:Type blockItemTypes:SoundBlockItem}" />
<DataTemplate DataType="{x:Type blockItemTypes:FontSizeBlockItem}" />
</ItemsControl.Resources>
</ItemsControl.ItemTemplate>
</ItemsControl>
</WrapPanel>
<Grid Grid.Row="2" Margin="0,5,0,5">

View File

@ -39,6 +39,7 @@
<converters:BooleanToBlockActionInverseConverter x:Key="BooleanToBlockActionInverseConverter" />
<converters:BlockItemTypeToStringConverter x:Key="BlockItemTypeToStringConverter" />
<converters:BooleanVisibilityConverter x:Key="BooleanVisibilityConverter" />
<converters:BlockItemToRemoveEnabledVisibilityConverter x:Key="BlockItemToRemoveEnabledVisibilityConverter" />
</ResourceDictionary>
<ResourceDictionary Source="ExpanderStyle.xaml" />
</ResourceDictionary.MergedDictionaries>