Files
bluflame/hgplus/bliss/Tweaky/PropertyGrid/PropertyGrid.xaml
2026-04-18 22:31:51 +02:00

159 lines
11 KiB
XML

<UserControl x:Class="Tweaky.PropertyGrid.PropertyGrid"
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:pg="clr-namespace:Tweaky.PropertyGrid"
xmlns:t="clr-namespace:Tweaky"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
mc:Ignorable="d"
x:Name="Me"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance Type={x:Type t:DataViewModel}}" >
<UserControl.Resources>
<pg:EditorTemplateSelector x:Key="EditorTemplateSelector" />
<Style x:Key="ClearFilterButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="{DynamicResource ForegroundGradient}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid Background="{DynamicResource PseudoTransparent}">
<Border x:Name="hoverBorder" CornerRadius="2" BorderBrush="{DynamicResource SeparatingBorder}" BorderThickness="1" Background="{DynamicResource ForegroundGradient}" Visibility="Collapsed" />
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="hoverBorder" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="hoverBorder" Property="Background" Value="{DynamicResource BrightGradient}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<CollectionViewSource Source="{Binding PropertyItems, ElementName=Me}" x:Key="collectionView" Filter="CollectionViewSource_Filter" CollectionViewType="ListCollectionView">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Category" Direction="Ascending" />
<scm:SortDescription PropertyName="Index" Direction="Ascending" />
</CollectionViewSource.SortDescriptions>
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Category" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Grid.RowSpan="2" Background="{DynamicResource BarGradient}" />
<StackPanel Orientation="Horizontal" Margin="13,0,0,2">
<TextBlock Foreground="{DynamicResource Foreground}" Text="{Binding ItemsSourceName, ElementName=Me}" MinWidth="50" Margin="0,1,0,0" TextBlock.FontWeight="Bold" VerticalAlignment="Center" />
<TextBlock Foreground="{DynamicResource Foreground}" Text="{Binding ItemsSourceType, ElementName=Me}" Margin="5,1,0,0" VerticalAlignment="Center" />
</StackPanel>
<Border Name="searchBoxContainer" Grid.Row="1" Margin="4" BorderThickness="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="Search:" VerticalAlignment="Center" Margin="3,0" Foreground="{DynamicResource Foreground}" />
<TextBox Grid.Column="1" Text="{Binding Filter, ElementName=Me, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
</Border>
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.Row="2" CanContentScroll="False">
<ItemsControl x:Name="PART_PropertyItemsControl" IsTabStop="False" Focusable="False" VerticalAlignment="Top" ItemsSource="{Binding Source={StaticResource collectionView}}">
<ItemsControl.Resources>
<Style TargetType="{x:Type ScrollViewer}" BasedOn="{StaticResource {x:Type ScrollViewer}}">
<Setter Property="HorizontalScrollBarVisibility" Value="Hidden" />
<Setter Property="VerticalScrollBarVisibility" Value="Hidden" />
<Setter Property="CanContentScroll" Value="False" />
</Style>
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Border>
<Expander IsExpanded="True">
<Expander.Header>
<TextBlock Foreground="{DynamicResource Foreground}" Text="{Binding Name}" />
</Expander.Header>
<ItemsPresenter Margin="10,0,0,0" />
</Expander>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ItemsControl.GroupStyle>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type pg:PropertyItem}">
<Border x:Name="MainBorder" ContextMenuService.Placement="Bottom" SnapsToDevicePixels="True" UseLayoutRounding="False" Background="{DynamicResource PseudoTransparent}" PreviewMouseDown="PropertyItem_PreviewMouseDown">
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border Name="PART_Name" VerticalAlignment="Stretch" Margin="0,0,0,1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="10" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
<TextBlock VerticalAlignment="Center" Text="{Binding Name}" Foreground="{DynamicResource Foreground}" />
<TextBlock VerticalAlignment="Center" Text=":" Foreground="{DynamicResource Foreground}" />
</StackPanel>
</Grid>
</Border>
<Border Name="PART_Editor" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,0,1,0">
<ContentPresenter ContentTemplateSelector="{StaticResource EditorTemplateSelector}" Content="{Binding}" SnapsToDevicePixels="True" UseLayoutRounding="False" />
<!--<TextBox Name="PART_ValueContainer" MaxLines="1" PreviewMouseWheel="PART_ValueContainer_PreviewMouseWheel" Text="{Binding Value, Mode=TwoWay}" Focusable="False" IsTabStop="False" IsEnabled="{Binding IsReadOnly, Converter={StaticResource InvBooleanToVisibilityConverter}}" TextOptions.TextFormattingMode="Display" />-->
</Border>
</Grid>
</Border>
<DataTemplate.Triggers>
<Trigger Property="UIElement.IsMouseOver" Value="True">
<Setter TargetName="MainBorder" Property="Border.Background" Value="{DynamicResource LightGradient}" />
</Trigger>
<DataTrigger Binding="{Binding IsSelected}" Value="True">
<Setter TargetName="MainBorder" Property="Border.Background" Value="{DynamicResource BrightGradient}" />
</DataTrigger>
<!--<Trigger Property="UIElement.IsEnabled" Value="False">
<Setter TargetName="PART_ValueContainer" Value="{DynamicResource DisabledForegroundBrush}" Property="Control.Foreground" />
</Trigger>-->
<Trigger Property="Validation.HasError" Value="True">
<Setter Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors).CurrentItem.ErrorContent}" Property="FrameworkElement.ToolTip" />
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<GridSplitter Grid.Row="3" Height="5" ResizeBehavior="PreviousAndNext" HorizontalAlignment="Stretch" Background="{DynamicResource PseudoTransparent}" ResizeDirection="Rows" />
<StackPanel Grid.Row="4" Margin="0,0,0,5">
<TextBlock Foreground="{DynamicResource Foreground}" Padding="2 2 2 0" TextBlock.FontWeight="Bold" Text="{Binding SelectedPropertyItem.Name, ElementName=Me}" />
<TextBlock Foreground="{DynamicResource Foreground}" Padding="5 2 2 0" TextWrapping="WrapWithOverflow" Text="{Binding SelectedPropertyItem.Description, ElementName=Me}" />
</StackPanel>
</Grid>
</UserControl>