14 changed files with 359 additions and 166 deletions
|
After Width: | Height: | Size: 682 B |
@ -0,0 +1,24 @@ |
|||
<Window x:Class="Microsoft.Windows.Controls.CollectionEditorDialog" |
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:extToolkit="clr-namespace:Microsoft.Windows.Controls" |
|||
xmlns:propertyGrid="clr-namespace:Microsoft.Windows.Controls.PropertyGrid" |
|||
Title="Collection Editor" Height="400" Width="600" WindowStartupLocation="CenterScreen"> |
|||
|
|||
<Grid Margin="10"> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="*" /> |
|||
<RowDefinition Height="Auto" /> |
|||
</Grid.RowDefinitions> |
|||
|
|||
<extToolkit:CollectionEditor x:Name="_propertyGrid" |
|||
ItemsSourceType="{Binding ItemsSourceType, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" |
|||
ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"/> |
|||
|
|||
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right" Margin="5" > |
|||
<Button Width="75" Margin="2" Click="OkButton_Click" IsDefault="True">OK</Button> |
|||
<Button Width="75" Margin="2" IsCancel="True">Cancel</Button> |
|||
</StackPanel> |
|||
|
|||
</Grid> |
|||
</Window> |
|||
@ -0,0 +1,55 @@ |
|||
using System; |
|||
using System.Windows; |
|||
using System.Collections; |
|||
|
|||
namespace Microsoft.Windows.Controls |
|||
{ |
|||
/// <summary>
|
|||
/// Interaction logic for CollectionEditorDialog.xaml
|
|||
/// </summary>
|
|||
public partial class CollectionEditorDialog : Window |
|||
{ |
|||
#region Properties
|
|||
|
|||
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IList), typeof(CollectionEditorDialog), new UIPropertyMetadata(null)); |
|||
public IList ItemsSource |
|||
{ |
|||
get { return (IList)GetValue(ItemsSourceProperty); } |
|||
set { SetValue(ItemsSourceProperty, value); } |
|||
} |
|||
|
|||
public static readonly DependencyProperty ItemsSourceTypeProperty = DependencyProperty.Register("ItemsSourceType", typeof(Type), typeof(CollectionEditorDialog), new UIPropertyMetadata(null)); |
|||
public Type ItemsSourceType |
|||
{ |
|||
get { return (Type)GetValue(ItemsSourceTypeProperty); } |
|||
set { SetValue(ItemsSourceTypeProperty, value); } |
|||
} |
|||
|
|||
#endregion //Properties
|
|||
|
|||
#region Constructors
|
|||
|
|||
public CollectionEditorDialog() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
public CollectionEditorDialog(Type type) |
|||
: this() |
|||
{ |
|||
ItemsSourceType = type; |
|||
} |
|||
|
|||
#endregion //Constructors
|
|||
|
|||
#region Event Handlers
|
|||
|
|||
private void OkButton_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
_propertyGrid.PersistChanges(); |
|||
Close(); |
|||
} |
|||
|
|||
#endregion //Event Hanlders
|
|||
} |
|||
} |
|||
@ -0,0 +1,90 @@ |
|||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:local="clr-namespace:Microsoft.Windows.Controls" |
|||
xmlns:coreConverters="clr-namespace:Microsoft.Windows.Controls.Core.Converters" |
|||
xmlns:propertyGrid="clr-namespace:Microsoft.Windows.Controls.PropertyGrid"> |
|||
|
|||
<coreConverters:ObjectTypeToNameConverter x:Key="ObjectTypeToNameConverter" /> |
|||
|
|||
<Style x:Key="CollectionEditorButtonStyle" TargetType="{x:Type Button}"> |
|||
<Style.Triggers> |
|||
<Trigger Property="IsEnabled" Value="false"> |
|||
<Setter Property="Opacity" Value="0.6" /> |
|||
</Trigger> |
|||
</Style.Triggers> |
|||
<Setter Property="HorizontalContentAlignment" Value="Center" /> |
|||
<Setter Property="VerticalContentAlignment" Value="Center" /> |
|||
<Setter Property="Height" Value="26" /> |
|||
<Setter Property="Width" Value="26" /> |
|||
</Style> |
|||
|
|||
<Style TargetType="{x:Type local:CollectionEditor}"> |
|||
<Setter Property="Template"> |
|||
<Setter.Value> |
|||
<ControlTemplate TargetType="{x:Type local:CollectionEditor}"> |
|||
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> |
|||
<Grid> |
|||
<Grid.ColumnDefinitions> |
|||
<ColumnDefinition Width="*" /> |
|||
<ColumnDefinition Width="1.5*" /> |
|||
</Grid.ColumnDefinitions> |
|||
<Grid> |
|||
<Grid.ColumnDefinitions> |
|||
<ColumnDefinition /> |
|||
<ColumnDefinition Width="Auto" /> |
|||
<ColumnDefinition Width="Auto" /> |
|||
</Grid.ColumnDefinitions> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="Auto" /> |
|||
<RowDefinition Height="Auto" /> |
|||
<RowDefinition /> |
|||
</Grid.RowDefinitions> |
|||
<TextBlock Margin="0,0,0,5" Text="Select type:" /> |
|||
<ComboBox x:Name="_newItemTypes" Grid.Row="1" Margin="0,0,0,3" HorizontalAlignment="Stretch" |
|||
ItemsSource="{Binding NewItemTypes, RelativeSource={RelativeSource TemplatedParent}}" |
|||
DisplayMemberPath="Name" |
|||
SelectedIndex="0"/> |
|||
<Button Margin="3,0,0,3" Grid.Row="1" Grid.Column="1" Padding="5,0" Content="Add" |
|||
Command="New" CommandParameter="{Binding SelectedItem, ElementName=_newItemTypes}" /> |
|||
<ListBox x:Name="_itemsListBox" Grid.Row="2" Grid.ColumnSpan="2" |
|||
ItemsSource="{Binding Items, RelativeSource={RelativeSource TemplatedParent}}" |
|||
SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource TemplatedParent}}" |
|||
SelectedIndex="0"> |
|||
<ListBox.ItemTemplate> |
|||
<DataTemplate> |
|||
<TextBlock Text="{Binding Converter={StaticResource ObjectTypeToNameConverter}}" /> |
|||
</DataTemplate> |
|||
</ListBox.ItemTemplate> |
|||
</ListBox> |
|||
<StackPanel Margin="7,2,0,0" VerticalAlignment="Top" Grid.Column="2" Grid.Row="2"> |
|||
<Button Style="{StaticResource CollectionEditorButtonStyle}" |
|||
Command="ComponentCommands.MoveUp" CommandParameter="{Binding SelectedItem, ElementName=_itemsListBox}"> |
|||
<Path Fill="#FF404040" Data="F0 M 6,0 L 12,7 8,7 8,12 4,12 4,7 0,7 Z" /> |
|||
</Button> |
|||
<Button Margin="0,1,0,0" Style="{StaticResource CollectionEditorButtonStyle}" |
|||
Command="ComponentCommands.MoveDown" CommandParameter="{Binding SelectedItem, ElementName=_itemsListBox}"> |
|||
<Path Fill="#FF404040" Data="F0 M 4,0 L 8,0 8,5 12,5 6,12 0,5 4,5 Z" /> |
|||
</Button> |
|||
<Button Margin="0,7,0,0" Style="{StaticResource CollectionEditorButtonStyle}" |
|||
Command="Delete" CommandParameter="{Binding SelectedItem, ElementName=_itemsListBox}"> |
|||
<Image Stretch="None" Height="16" Width="16" Margin="1" Source="/WPFToolkit.Extended;component/CollectionEditors/Images/Delete16.png" /> |
|||
</Button> |
|||
</StackPanel> |
|||
</Grid> |
|||
<Grid Column="1" Margin="20,0,0,0"> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="Auto" /> |
|||
<RowDefinition /> |
|||
</Grid.RowDefinitions> |
|||
<TextBlock Grid.Column="1" Text="Properties:" /> |
|||
<propertyGrid:PropertyGrid Grid.Row="1" Grid.Column="1" Margin="0,5,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" |
|||
SelectedObject="{Binding SelectedItem, RelativeSource={RelativeSource TemplatedParent}}"/> |
|||
</Grid> |
|||
</Grid> |
|||
</Border> |
|||
</ControlTemplate> |
|||
</Setter.Value> |
|||
</Setter> |
|||
</Style> |
|||
|
|||
</ResourceDictionary> |
|||
@ -0,0 +1,17 @@ |
|||
using System; |
|||
using System.Windows.Data; |
|||
|
|||
namespace Microsoft.Windows.Controls.Core.Converters |
|||
{ |
|||
public class ObjectTypeToNameConverter : IValueConverter |
|||
{ |
|||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) |
|||
{ |
|||
return value.GetType().Name; |
|||
} |
|||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,81 +0,0 @@ |
|||
<Window x:Class="Microsoft.Windows.Controls.PropertyGrid.Editors.CollectionEditorDialog" |
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:propertyGrid="clr-namespace:Microsoft.Windows.Controls.PropertyGrid" |
|||
Title="Collection Editor" Height="400" Width="600" WindowStartupLocation="CenterScreen"> |
|||
|
|||
<Window.CommandBindings> |
|||
<CommandBinding Command="New" Executed="AddNew" CanExecute="CanAddNew" /> |
|||
<CommandBinding Command="Delete" Executed="Delete" CanExecute="CanDelete" /> |
|||
<CommandBinding Command="ComponentCommands.MoveDown" Executed="MoveDown" CanExecute="CanMoveDown" /> |
|||
<CommandBinding Command="ComponentCommands.MoveUp" Executed="MoveUp" CanExecute="CanMoveUp" /> |
|||
</Window.CommandBindings> |
|||
|
|||
<Grid Margin="10"> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="*" /> |
|||
<RowDefinition Height="Auto" /> |
|||
</Grid.RowDefinitions> |
|||
|
|||
<Grid> |
|||
<Grid.ColumnDefinitions> |
|||
<ColumnDefinition Width="Auto" /> |
|||
<ColumnDefinition Width="*"/> |
|||
</Grid.ColumnDefinitions> |
|||
|
|||
<Grid Margin="0,0,10,0" MinWidth="200"> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="Auto" /> |
|||
<RowDefinition Height="*" /> |
|||
</Grid.RowDefinitions> |
|||
|
|||
<Grid.ColumnDefinitions> |
|||
<ColumnDefinition Width="*" /> |
|||
<ColumnDefinition Width="Auto"/> |
|||
</Grid.ColumnDefinitions> |
|||
|
|||
<StackPanel> |
|||
<TextBlock Text="Select Type:" Margin="4" /> |
|||
<Grid> |
|||
<Grid.ColumnDefinitions> |
|||
<ColumnDefinition Width="*" /> |
|||
<ColumnDefinition Width="Auto" /> |
|||
</Grid.ColumnDefinitions> |
|||
<ComboBox x:Name="_newItemTypes" Margin="0,0,4,0" |
|||
ItemsSource="{Binding NewItemTypes}" |
|||
DisplayMemberPath="Name" |
|||
SelectedIndex="0"/> |
|||
<Button Content="Add" Grid.Column="1" Width="50" |
|||
Command="New" CommandParameter="{Binding SelectedItem, ElementName=_newItemTypes}"/> |
|||
</Grid> |
|||
</StackPanel> |
|||
|
|||
<ListBox x:Name="_listBox" Grid.Row="1" Margin="0,4,0,0" |
|||
ItemsSource="{Binding Items}" |
|||
SelectedIndex="0" |
|||
SelectedItem="{Binding SelectedItem}"/> |
|||
|
|||
<StackPanel Grid.Column="1" Grid.Row="1" Margin="5,4,0,0"> |
|||
<Button Command="ComponentCommands.MoveUp" CommandParameter="{Binding SelectedItem, ElementName=_listBox}">Up</Button> |
|||
<Button Command="ComponentCommands.MoveDown" CommandParameter="{Binding SelectedItem, ElementName=_listBox}">Down</Button> |
|||
<Button Command="Delete" CommandParameter="{Binding SelectedItem, ElementName=_listBox}" >Delete</Button> |
|||
</StackPanel> |
|||
</Grid> |
|||
|
|||
<Grid Grid.Column="1"> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="Auto" /> |
|||
<RowDefinition Height="*" /> |
|||
</Grid.RowDefinitions> |
|||
<TextBlock Text="Properties:" Margin="4" /> |
|||
<propertyGrid:PropertyGrid x:Name="_propertyGrid" Grid.Row="1" SelectedObject="{Binding SelectedItem}" /> |
|||
</Grid> |
|||
</Grid> |
|||
|
|||
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right" Margin="5" > |
|||
<Button Width="75" Margin="2" Click="OkButton_Click" IsDefault="True">OK</Button> |
|||
<Button Width="75" Margin="2" IsCancel="True">Cancel</Button> |
|||
</StackPanel> |
|||
|
|||
</Grid> |
|||
</Window> |
|||
Loading…
Reference in new issue