diff options
author | Eric Maupin <ermaup@microsoft.com> | 2018-04-27 23:45:27 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2018-05-01 01:00:32 +0300 |
commit | 31f4af0b1babf93cfad66617a84c1b85b8a3681b (patch) | |
tree | 5407abb1b8c8b3da5e3c1827c39e9307794ba81a /Xamarin.PropertyEditing.Windows | |
parent | ce0b16d6b4ed11bf89c054a0fba1f6b81e5de441 (diff) |
[Core/Win] Collection property editor
Diffstat (limited to 'Xamarin.PropertyEditing.Windows')
6 files changed, 148 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing.Windows/CollectionEditor.cs b/Xamarin.PropertyEditing.Windows/CollectionEditor.cs new file mode 100644 index 0000000..41f7c01 --- /dev/null +++ b/Xamarin.PropertyEditing.Windows/CollectionEditor.cs @@ -0,0 +1,34 @@ +using System; +using System.Windows; +using System.Windows.Controls.Primitives; + +namespace Xamarin.PropertyEditing.Windows +{ + [TemplatePart (Name = "launch", Type = typeof(ButtonBase))] + internal class CollectionEditor + : PropertyEditorControl + { + static CollectionEditor () + { + DefaultStyleKeyProperty.OverrideMetadata (typeof(CollectionEditor), new FrameworkPropertyMetadata (typeof(CollectionEditor))); + } + + public override void OnApplyTemplate () + { + base.OnApplyTemplate (); + + if (!(GetTemplateChild ("launch") is ButtonBase button)) + throw new InvalidOperationException ("Missing 'launch' button in CollectionEditor template"); + + var topLevel = this.FindPropertiesHost (); + + button.Click += (sender, args) => { + var window = new CollectionEditorWindow (topLevel.Resources.MergedDictionaries) { + DataContext = DataContext + }; + + window.ShowDialog (); + }; + } + } +} diff --git a/Xamarin.PropertyEditing.Windows/CollectionEditorWindow.xaml b/Xamarin.PropertyEditing.Windows/CollectionEditorWindow.xaml new file mode 100644 index 0000000..f6677b0 --- /dev/null +++ b/Xamarin.PropertyEditing.Windows/CollectionEditorWindow.xaml @@ -0,0 +1,50 @@ +<local:WindowEx x:Class="Xamarin.PropertyEditing.Windows.CollectionEditorWindow" x:ClassModifier="internal" + 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:local="clr-namespace:Xamarin.PropertyEditing.Windows" + xmlns:prop="clr-namespace:Xamarin.PropertyEditing.Properties;assembly=Xamarin.PropertyEditing" + mc:Ignorable="d" Background="{DynamicResource DialogBackgroundBrush}" Foreground="{DynamicResource DialogForegroundBrush}" + MinHeight="300" Height="500" MinWidth="500" Width="700" ShowIcon="False" ShowMaximize="False" ShowMinimize="False" + Title="{Binding Property.Name, StringFormat={x:Static prop:Resources.CollectionEditorTitle},Mode=OneTime}"> + <Grid Margin="12"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="*" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*" /> + <ColumnDefinition Width="*" /> + </Grid.ColumnDefinitions> + + <TextBlock Text="{x:Static prop:Resources.Items}" Grid.Row="0" Grid.Column="0" /> + <TextBlock Text="{x:Static prop:Resources.Properties}" Grid.Row="0" Grid.Column="1" Margin="12,0,0,0" /> + + <ListBox ItemsSource="{Binding Targets,Mode=OneTime}" SelectedItem="{Binding SelectedTarget,Mode=TwoWay}" Margin="0,4,0,0" Grid.Column="0" Grid.Row="1" /> + <Grid Grid.Row="2" Margin="0,12,0,0"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto" /> + <ColumnDefinition Width="*" /> + <ColumnDefinition Width="Auto" /> + </Grid.ColumnDefinitions> + + <StackPanel Orientation="Horizontal" Grid.Column="0"> + <Button Command="{Binding RemoveTargetCommand,Mode=OneTime}" ToolTip="{x:Static prop:Resources.RemoveItem}" MinWidth="29" FontFamily="Segoe UI Symbol" Content="❌" /> + <Button Command="{Binding MoveUpCommand,Mode=OneTime}" ToolTip="{x:Static prop:Resources.MoveItemUp}" AutomationProperties.Name="{x:Static prop:Resources.MoveItemUp}" MinWidth="29" Margin="4,0,0,0" FontFamily="Segoe UI Symbol" Content="⭡" /> + <Button Command="{Binding MoveDownCommand,Mode=OneTime}" ToolTip="{x:Static prop:Resources.MoveItemDown}" AutomationProperties.Name="{x:Static prop:Resources.MoveItemDown}" MinWidth="29" Margin="4,0,0,0" FontFamily="Segoe UI Symbol" Content="⭣" /> + </StackPanel> + <ComboBox Grid.Column="1" ItemsSource="{Binding SuggestedTypes}" DisplayMemberPath="Name" SelectedItem="{Binding SelectedType,Mode=TwoWay}" Margin="12,0,0,0" /> + <Button Grid.Column="2" Command="{Binding AddTargetCommand,Mode=OneTime}" Margin="4,0,0,0">Add</Button> + </Grid> + + <ItemsControl Margin="12,4,0,0" Style="{StaticResource PropertyListStyle}" ItemsSource="{Binding Panel.Properties}" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" /> + + <StackPanel Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal" Margin="0,4,0,0"> + <Button IsDefault="True" MinWidth="75" MinHeight="23" Content="{x:Static prop:Resources.OK}" Command="{Binding CommitCommand,Mode=OneTime}" Click="OnOkClick" /> + <Button Margin="5,0,0,0" MinWidth="75" MinHeight="23" IsCancel="True" Content="{x:Static prop:Resources.Cancel}" /> + </StackPanel> + </Grid> +</local:WindowEx> diff --git a/Xamarin.PropertyEditing.Windows/CollectionEditorWindow.xaml.cs b/Xamarin.PropertyEditing.Windows/CollectionEditorWindow.xaml.cs new file mode 100644 index 0000000..4e1a166 --- /dev/null +++ b/Xamarin.PropertyEditing.Windows/CollectionEditorWindow.xaml.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Windows; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Windows +{ + internal partial class CollectionEditorWindow + : WindowEx, IPropertiesHost + { + public CollectionEditorWindow (IEnumerable<ResourceDictionary> mergedResources) + { + Resources.MergedDictionaries.AddItems (mergedResources); + InitializeComponent (); + DataContextChanged += OnDataContextChanged; + } + + private void OnDataContextChanged (object sender, DependencyPropertyChangedEventArgs e) + { + if (e.OldValue is CollectionPropertyViewModel oldVm) + oldVm.TypeRequested -= OnTypeRequested; + + if (e.NewValue is CollectionPropertyViewModel vm) + vm.TypeRequested += OnTypeRequested; + } + + private void OnTypeRequested (object sender, TypeRequestedEventArgs args) + { + args.SelectedType = TypeSelectorWindow.RequestType (this, ((CollectionPropertyViewModel)DataContext).AssignableTypes); + } + + private void OnOkClick (object sender, RoutedEventArgs e) + { + DialogResult = true; + } + } +} diff --git a/Xamarin.PropertyEditing.Windows/EditorPropertySelector.cs b/Xamarin.PropertyEditing.Windows/EditorPropertySelector.cs index c4550e4..22118c3 100644 --- a/Xamarin.PropertyEditing.Windows/EditorPropertySelector.cs +++ b/Xamarin.PropertyEditing.Windows/EditorPropertySelector.cs @@ -110,6 +110,7 @@ namespace Xamarin.PropertyEditing.Windows { typeof(BrushPropertyViewModel), typeof(BrushEditorControl) }, { typeof(PropertyGroupViewModel), typeof(GroupEditorControl) }, { typeof(ObjectPropertyViewModel), typeof(ObjectEditorControl) }, + { typeof(CollectionPropertyViewModel), typeof(CollectionEditor) }, }; } diff --git a/Xamarin.PropertyEditing.Windows/Themes/Resources.xaml b/Xamarin.PropertyEditing.Windows/Themes/Resources.xaml index 37e2d0a..9f6227a 100644 --- a/Xamarin.PropertyEditing.Windows/Themes/Resources.xaml +++ b/Xamarin.PropertyEditing.Windows/Themes/Resources.xaml @@ -1441,6 +1441,24 @@ </Style.Triggers> </Style> + <Style TargetType="local:CollectionEditor"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="local:CollectionEditor"> + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*" /> + <ColumnDefinition Width="Auto" /> + </Grid.ColumnDefinitions> + + <TextBlock Text="{x:Static prop:Resources.CollectionValue}" Grid.Column="0" /> + <Button Name="launch" Content="{x:Static prop:Resources.Ellipsis}" MinWidth="20" Grid.Column="1" /> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + <Style TargetType="local:PropertyPresenter"> <Setter Property="Background" Value="{DynamicResource PanelBackgroundBrush}" /> <Setter Property="Template"> diff --git a/Xamarin.PropertyEditing.Windows/Xamarin.PropertyEditing.Windows.csproj b/Xamarin.PropertyEditing.Windows/Xamarin.PropertyEditing.Windows.csproj index cd1a483..659634c 100644 --- a/Xamarin.PropertyEditing.Windows/Xamarin.PropertyEditing.Windows.csproj +++ b/Xamarin.PropertyEditing.Windows/Xamarin.PropertyEditing.Windows.csproj @@ -65,6 +65,10 @@ <Compile Include="BrushTabbedEditorControl.cs" /> <Compile Include="BrushToDarknessConverter.cs" /> <Compile Include="CategoryExpander.cs" /> + <Compile Include="CollectionEditor.cs" /> + <Compile Include="CollectionEditorWindow.xaml.cs"> + <DependentUpon>CollectionEditorWindow.xaml</DependentUpon> + </Compile> <Compile Include="CombinablePredefinedValuesEditorControl.cs" /> <Compile Include="CommonBrushToBrushConverter.cs" /> <Compile Include="ByteToPercentageConverter.cs" /> @@ -126,6 +130,10 @@ <Compile Include="XamlHelper.cs" /> </ItemGroup> <ItemGroup> + <Page Include="CollectionEditorWindow.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="ResourceSelectorWindow.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> |