Merge pull request #83 from simplic/FlatCollectionCombobox
Add a Combobox in FlatCollectonEditor.
This commit is contained in:
Коммит
b87b18b8b1
|
@ -39,13 +39,21 @@
|
|||
SelectionChanged="ListBox_SelectionChanged" ItemTemplateSelector="{StaticResource CollectionTemplateSelector}">
|
||||
</ListBox>
|
||||
</Border>
|
||||
<ComboBox Name="ItemDataType"
|
||||
Grid.Column="1"
|
||||
Height="23"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Width="75" Margin="0,10,0,0">
|
||||
|
||||
</ComboBox>
|
||||
<Button
|
||||
Content="Add"
|
||||
Click="OnAddItemClicked"
|
||||
Grid.Column="1"
|
||||
Height="23"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="0,12,0,0"
|
||||
Margin="0,40,0,0"
|
||||
Name="AddItem"
|
||||
VerticalAlignment="Top"
|
||||
Width="75" />
|
||||
|
@ -55,7 +63,7 @@
|
|||
Grid.Column="1"
|
||||
Height="23"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="0,42,0,0"
|
||||
Margin="0,68,0,0"
|
||||
Name="RemoveItem"
|
||||
VerticalAlignment="Top"
|
||||
Width="75" />
|
||||
|
@ -65,7 +73,7 @@
|
|||
Grid.Column="1"
|
||||
Height="23"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="0,72,0,0"
|
||||
Margin="0,96,0,0"
|
||||
Name="MoveUpItem"
|
||||
VerticalAlignment="Top"
|
||||
Width="75" />
|
||||
|
@ -75,10 +83,10 @@
|
|||
Grid.Column="1"
|
||||
Height="23"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="0,102,0,0"
|
||||
Margin="0,124,0,0"
|
||||
Name="MoveDownItem"
|
||||
VerticalAlignment="Top"
|
||||
Width="75" />
|
||||
Width="75" RenderTransformOrigin="0.519,1.16" />
|
||||
<Border
|
||||
BorderBrush="Black"
|
||||
BorderThickness="0.75"
|
||||
|
|
|
@ -22,6 +22,7 @@ using System.Windows;
|
|||
using System.Windows.Controls;
|
||||
using System.Linq;
|
||||
using ICSharpCode.WpfDesign.Designer.themes;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
|
||||
{
|
||||
|
@ -45,7 +46,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
|
|||
public FlatCollectionEditor()
|
||||
{
|
||||
SpecialInitializeComponent();
|
||||
|
||||
|
||||
this.Owner = Application.Current.MainWindow;
|
||||
}
|
||||
|
||||
|
@ -59,7 +60,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
|
|||
Uri resourceLocator = new Uri(VersionedAssemblyResourceDictionary.GetXamlNameForType(this.GetType()), UriKind.Relative);
|
||||
Application.LoadComponent(this, resourceLocator);
|
||||
}
|
||||
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
|
@ -84,10 +84,33 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
|
|||
|
||||
ListBox.ItemsSource = _itemProperty.CollectionElements;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A method which fill a combobox with _type and the inherited classes.
|
||||
/// </summary>
|
||||
public void LoadItemsCombobox()
|
||||
{
|
||||
ItemDataType.Items.Add(_type);
|
||||
ItemDataType.SelectedItem = ItemDataType.Items[0];
|
||||
foreach (var items in GetInheritedClasses(_type))
|
||||
ItemDataType.Items.Add(items);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A Method to find all inherited classes.
|
||||
/// </summary>
|
||||
/// <param name="MyType">The type where we want the inherited classes.</param>
|
||||
/// <returns>All inherited classes.</returns>
|
||||
private IEnumerable<Type> GetInheritedClasses(Type MyType)
|
||||
{
|
||||
return Assembly.GetAssembly(MyType).GetTypes().Where(TheType => TheType.IsClass && !TheType.IsAbstract && TheType.IsSubclassOf(MyType));
|
||||
}
|
||||
|
||||
private void OnAddItemClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DesignItem newItem = _componentService.RegisterComponentForDesigner(Activator.CreateInstance(_type));
|
||||
var comboboxItem = ItemDataType.SelectedItem;
|
||||
DesignItem newItem = _componentService.RegisterComponentForDesigner(Activator.CreateInstance((Type)comboboxItem));
|
||||
_itemProperty.CollectionElements.Add(newItem);
|
||||
}
|
||||
|
||||
|
@ -133,5 +156,9 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
|
|||
{
|
||||
PropertyGridView.PropertyGrid.SelectedItems = ListBox.SelectedItems.Cast<DesignItem>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
|
|||
|
||||
var editor = new FlatCollectionEditor();
|
||||
editor.LoadItemsCollection(node.FirstProperty);
|
||||
editor.LoadItemsCombobox();
|
||||
editor.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче