Files
Speckle.Material.Avalonia/Material.Styles/ComboBox.xaml
T
2022-06-03 06:24:00 +09:00

519 lines
30 KiB
XML

<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:assists="clr-namespace:Material.Styles.Assists"
xmlns:naming="clr-namespace:Material.Styles.Resources.Naming"
xmlns:converters="clr-namespace:Material.Styles.Converters"
xmlns:parameters="clr-namespace:Material.Styles.Converters.Parameters"
xmlns:controls="clr-namespace:Material.Styles.Controls">
<Styles.Resources>
<converters:RectHollowClipConverter x:Key="RectangleHollowGeometry" />
<parameters:RectHollowClipParameter x:Key="OutlineTextBoxClippingParameter" Margin="8,0" Offset="4,-8"/>
</Styles.Resources>
<!-- TODO: Rework combobox styles-->
<Style Selector="ComboBox">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="PlaceholderForeground" Value="{DynamicResource MaterialDesignBody}"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Padding" Value="8,4" />
<Setter Property="ClipToBounds" Value="False" />
<Setter Property="Template">
<ControlTemplate>
<Border Name="{x:Static naming:PartNames.PartRootBorder}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Panel Name="{x:Static naming:PartNames.PartRootPanel}">
<Border Name="PART_BackgroundField">
<Border.Styles>
<Style Selector="ComboBox.outline:not(.material-combobox-no-label) /template/
Border#PART_BackgroundTextField">
<Setter Property="Clip">
<MultiBinding Converter="{StaticResource RectangleHollowGeometry}"
ConverterParameter="{StaticResource OutlineTextBoxClippingParameter}"
RelativeSource="{RelativeSource AncestorType=TextBox}">
<Binding ElementName="PART_TextFieldPanel" Path="Bounds"/>
<Binding ElementName="PART_LabelRootBorder" Path="Bounds"/>
<Binding ElementName="PART_LabelRootBorder" Path="RenderTransform"/>
</MultiBinding>
</Setter>
</Style>
</Border.Styles>
</Border>
<Panel Name="{x:Static naming:PartNames.PartInnerPanel}">
<TextBlock Name="{x:Static naming:PartNames.PartPlaceholderText}"
Text="{TemplateBinding PlaceholderText}"
Foreground="{TemplateBinding PlaceholderForeground}"/>
<ContentPresenter Name="{x:Static naming:PartNames.PartContentPresenter}"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding ItemTemplate}"/>
</Panel>
<Border Name="{x:Static naming:PartNames.PartLabelRootBorder}">
<TextBlock Name="{x:Static naming:PartNames.PartLabelText}"
Text="{TemplateBinding (assists:ComboBoxAssist.Label)}" />
</Border>
<controls:MaterialUnderline Name="{x:Static naming:PartNames.PartUnderline}"
Classes="material-mirror-y"/>
<Panel Name="PART_PopupContainer">
<Popup Name="{x:Static naming:PartNames.PartPopup}"
IsOpen="{TemplateBinding IsDropDownOpen, Mode=TwoWay}">
<controls:Card Name="{x:Static naming:PartNames.PartCard}"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}">
<ScrollViewer Name="{x:Static naming:PartNames.PartScrollViewer}">
<ItemsPresenter Name="{x:Static naming:PartNames.PartItemsPresenter}"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}"
VirtualizationMode="{TemplateBinding VirtualizationMode}" />
</ScrollViewer>
</controls:Card>
</Popup>
</Panel>
</Panel>
</Border>
<!-- deprecated style
<Grid Name="templateRoot"
Background="{TemplateBinding Background}"
ClipToBounds="False">
<Grid ColumnDefinitions="*,Auto" ClipToBounds="False">
<ToggleButton Name="toggle"
Classes="ComboBoxToggleButton"
BorderThickness="0"
Background="Transparent"
Focusable="False"
BorderBrush="{DynamicResource MaterialDesignTextBoxBorder}"
IsChecked="{TemplateBinding IsDropDownOpen, Mode=TwoWay}"
Grid.ColumnSpan="2" />
<Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}"
UseLayoutRounding="{TemplateBinding UseLayoutRounding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Name="InputRoot"
HorizontalAlignment="Stretch">
<TextBlock Name="placeholderText" Text="{TemplateBinding PlaceholderText}"
TextAlignment="Left" FontFamily="{TemplateBinding FontFamily}" Margin="0,4" />
<ContentPresenter Name="contentPresenter"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding ItemTemplate}"
HorizontalContentAlignment="Left"
Margin="0, 4" />
</Grid>
</Grid>
<Popup Name="PART_Popup"
IsOpen="{TemplateBinding IsDropDownOpen, Mode=TwoWay}"
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
VerticalOffset="0"
Margin="-8"
WindowManagerAddShadowHint="False"
PlacementTarget="{Binding ElementName=templateRoot}"
IsLightDismissEnabled="True"
UseLayoutRounding="True"
ClipToBounds="False">
<cc:Card assists:ShadowAssist.ShadowDepth="Depth1"
Margin="4,0,4,4"
CornerRadius="0,0,4,4"
Padding="0">
<ScrollViewer Background="{Binding Background, ElementName=PART_Popup}"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinHeight="1">
<ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}"
VirtualizationMode="{TemplateBinding VirtualizationMode}" />
</ScrollViewer>
</cc:Card>
</Popup>
</Grid>
</Grid>
-->
</ControlTemplate>
</Setter>
</Style>
<Style Selector="ComboBox /template/ Panel#PART_RootPanel">
<Setter Property="Height" Value="56"/>
</Style>
<Style Selector="ComboBox /template/ controls|MaterialUnderline#PART_Underline" >
<Setter Property="VerticalAlignment" Value="Bottom"/>
</Style>
<Style Selector="ComboBox:focus-within /template/ controls|MaterialUnderline#PART_Underline,
ComboBox[IsDropDownOpen=True] /template/ controls|MaterialUnderline#PART_Underline" >
<Setter Property="IsActive" Value="True"/>
</Style>
<Style Selector="ComboBox:pointerover /template/ controls|MaterialUnderline#PART_Underline" >
<Setter Property="IsHovered" Value="True"/>
</Style>
<Style Selector="ComboBox /template/ TextBlock#PART_PlaceholderText">
<Setter Property="Opacity" Value="0" />
</Style>
<Style Selector="ComboBox[SelectedIndex=-1] /template/ TextBlock#PART_PlaceholderText">
<Setter Property="Opacity" Value="1" />
</Style>
<Style Selector="ComboBox /template/ Popup#PART_Popup">
<Setter Property="Margin" Value="6,0"/>
</Style>
<Style Selector="ComboBox /template/ Panel#PART_PopupContainer">
<Setter Property="Margin" Value="-6,0"/>
</Style>
<Style Selector="ComboBox /template/ Popup#PART_Popup > controls|Card#PART_Card">
<Setter Property="Padding" Value="0"/>
<Setter Property="Margin" Value="6,0,6,6"/>
<Setter Property="CornerRadius" Value="0,0,4,4"/>
</Style>
<Style Selector="ToggleButton.ComboBoxToggleButton">
<Setter Property="Foreground" Value="{DynamicResource PrimaryHueMidForegroundBrush}" />
<Setter Property="Background" Value="{DynamicResource PrimaryHueMidBrush}" />
<Setter Property="assists:ToggleButtonAssist.UncheckedBackground" Value="{DynamicResource MaterialDesignPaper}" />
<Setter Property="assists:ToggleButtonAssist.UncheckedForeground" Value="{DynamicResource MaterialDesignBody}" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Padding" Value="16 4 16 4" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="ClickMode" Value="Press" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid Margin="4,0">
<Border Name="ToggleTemplateRoot"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<Border Name="splitBorder"
Margin="0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
BorderBrush="Transparent"
BorderThickness="0">
<Path Name="arrow"
Width="8" Height="8"
Margin="0"
Stretch="Uniform"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Data="M7,10L12,15L17,10H7Z"
Fill="{TemplateBinding BorderBrush}" />
</Border>
</Border>
<controls:MaterialUnderline Classes="material-mirror-y"
VerticalAlignment="Bottom"
Focusable="False" IsHitTestVisible="False"
Name="Underline">
<controls:MaterialUnderline.Styles>
<Style
Selector="ToggleButton.ComboBoxToggleButton:pointerover /template/ controls|MaterialUnderline#Underline,
ToggleButton.ComboBoxToggleButton:checked /template/ controls|MaterialUnderline#Underline">
<Setter Property="IsActive" Value="True" />
</Style>
</controls:MaterialUnderline.Styles>
</controls:MaterialUnderline>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style Selector="ComboBox.Filled">
<Setter Property="Background" Value="{DynamicResource MaterialDesignTextFieldBoxBackground}" />
<Setter Property="ContextMenu" Value="{StaticResource DefaultTextBoxContextMenu}" />
<Setter Property="FontFamily" Value="avares://Material.Styles/Fonts/Roboto#Roboto" />
<Setter Property="Padding" Value="16,8" />
<Setter Property="Template">
<ControlTemplate>
<StackPanel>
<ToggleButton Classes="NoFeedback TransparentBack"
MinHeight="48" BorderThickness="0"
HorizontalContentAlignment="Stretch"
IsChecked="{TemplateBinding IsDropDownOpen, Mode=TwoWay}"
Margin="4,0"
CornerRadius="4,4,0,0"
Padding="0">
<Border Name="border"
MinHeight="48"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Border.Styles>
<Style Selector="Border:disabled, TextBlock:disabled">
<Setter Property="Opacity" Value="0.5" />
</Style>
</Border.Styles>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TextBlock Name="floatingWatermark"
VerticalAlignment="Top"
HorizontalAlignment="Stretch"
Classes="Subtitle1"
Foreground="{DynamicResource ThemeAccentBrush}"
FontSize="{DynamicResource FontSizeSmall}"
Text="{TemplateBinding PlaceholderText}"
RenderTransformOrigin="0, 0">
<TextBlock.Styles>
<Style Selector="TextBlock#floatingWatermark:not(.no-transitions)">
<Setter Property="Transitions">
<Transitions>
<ThicknessTransition Duration="0:0:0.25" Property="Margin"
Easing="CubicEaseOut" />
<TransformOperationsTransition Property="RenderTransform"
Duration="0:0:0.25" Easing="CubicEaseOut" />
</Transitions>
</Setter>
</Style>
</TextBlock.Styles>
</TextBlock>
<Grid ColumnDefinitions="*,Auto">
<ContentPresenter Name="contentPresenter"
BorderThickness="0" BorderBrush="Transparent"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding ItemTemplate}"
Margin="{TemplateBinding Padding}" />
<Border Name="splitBorder"
Grid.Column="1"
Margin="16"
HorizontalAlignment="Right"
VerticalAlignment="Center"
BorderBrush="Transparent"
BorderThickness="0">
<Path Name="arrow"
Width="8" Height="8"
Stretch="Uniform"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Data="M7,10L12,15L17,10H7Z"
Fill="{DynamicResource MaterialDesignTextBoxBorder}" />
</Border>
</Grid>
<controls:MaterialUnderline Classes="MirrorY"
VerticalAlignment="Bottom"
Name="Underline">
<controls:MaterialUnderline.Styles>
<Style
Selector="ComboBox.Filled[IsDropDownOpen=true] /template/ controls|MaterialUnderline#Underline,
ComboBox.Filled:pointerover /template/ controls|MaterialUnderline#Underline">
<Setter Property="IsActive" Value="True" />
</Style>
</controls:MaterialUnderline.Styles>
</controls:MaterialUnderline>
</Grid>
</Border>
</ToggleButton>
<Popup Name="PART_Popup"
IsOpen="{TemplateBinding IsDropDownOpen, Mode=TwoWay}"
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
VerticalOffset="0"
Margin="0"
WindowManagerAddShadowHint="False"
PlacementTarget="{Binding ElementName=templateRoot}"
IsLightDismissEnabled="True"
UseLayoutRounding="True"
ClipToBounds="False">
<controls:Card assists:ShadowAssist.ShadowDepth="Depth1"
Margin="4,0,4,4"
CornerRadius="0,0,8,8"
Padding="0">
<ScrollViewer Background="{Binding Background, ElementName=PART_Popup}"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinHeight="1">
<ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}"
VirtualizationMode="{TemplateBinding VirtualizationMode}" />
</ScrollViewer>
</controls:Card>
</Popup>
</StackPanel>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="ComboBox.Filled[IsDropDownOpen=true] /template/ TextBlock#floatingWatermark">
<Setter Property="Margin" Value="10,10,1,1" />
<Setter Property="RenderTransform" Value="scale(0.75)" />
</Style>
<Style Selector="ComboBox.Filled[IsDropDownOpen=false] /template/ TextBlock#floatingWatermark">
<Setter Property="Margin" Value="10,20,1,1" />
</Style>
<Style Selector="ComboBox.Outline">
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignBody }" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="ContextMenu" Value="{StaticResource DefaultTextBoxContextMenu}" />
<Setter Property="FontFamily" Value="avares://Material.Styles/Fonts/Roboto#Roboto" />
<Setter Property="Padding" Value="16,8" />
<Setter Property="Template">
<ControlTemplate>
<StackPanel>
<Grid RowDefinitions="*, Auto">
<Grid Name="PART_RootBorder"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="Transparent"
Margin="0,8,0,0"
ClipToBounds="False">
<Border Name="PART_Border" CornerRadius="4"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}">
<Border.Clip>
<MultiBinding Converter="{StaticResource RectangleHollowGeometry}">
<Binding ElementName="PART_Border" Path="Bounds" />
<Binding ElementName="watermarkRoot" Path="Bounds" />
<Binding ElementName="watermarkRoot" Path="TransformedBounds" />
</MultiBinding>
</Border.Clip>
</Border>
<Border Name="watermarkRoot"
HorizontalAlignment="Left" VerticalAlignment="Top"
RenderTransformOrigin="0, 0" Opacity="1">
<TextBlock Name="floatingWatermark" Classes="Subtitle1"
HorizontalAlignment="Stretch" Margin="4,2"
Foreground="{TemplateBinding BorderBrush}"
Opacity="{Binding ElementName=PART_Border, Path=Opacity}"
Text="{TemplateBinding (assists:ComboBoxAssist.Label)}" />
</Border>
<Grid ColumnDefinitions="*,Auto">
<ContentPresenter Name="contentPresenter"
BorderThickness="0" BorderBrush="Transparent"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding ItemTemplate}"
Margin="{TemplateBinding Padding}" />
<Border Name="splitBorder"
Grid.Column="1"
Margin="16"
HorizontalAlignment="Right"
VerticalAlignment="Center"
BorderBrush="Transparent"
BorderThickness="0">
<Path Name="arrow"
Width="8" Height="8"
Stretch="Uniform"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Data="M7,10L12,15L17,10H7Z"
Fill="{DynamicResource MaterialDesignTextBoxBorder}" />
</Border>
</Grid>
</Grid>
</Grid>
<Popup Name="PART_Popup"
IsOpen="{TemplateBinding IsDropDownOpen, Mode=TwoWay}"
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
VerticalOffset="0"
Margin="0"
WindowManagerAddShadowHint="False"
PlacementTarget="{Binding ElementName=templateRoot}"
IsLightDismissEnabled="True"
UseLayoutRounding="True"
ClipToBounds="False">
<controls:Card assists:ShadowAssist.ShadowDepth="Depth1"
Margin="4,0,4,4"
CornerRadius="8"
Padding="0">
<ScrollViewer Background="{Binding Background, ElementName=PART_Popup}"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinHeight="1">
<ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}"
VirtualizationMode="{TemplateBinding VirtualizationMode}" />
</ScrollViewer>
</controls:Card>
</Popup>
</StackPanel>
</ControlTemplate>
</Setter>
</Style>
<!-- Transitions -->
<Style
Selector="ComboBox.Outline:not(.no-transitions) /template/ TextBlock#floatingWatermark,
ComboBox.Outline:not(.no-transitions) /template/ Border#watermarkRoot">
<Setter Property="Transitions">
<Transitions>
<ThicknessTransition Duration="0:0:0.25" Property="Margin" Easing="CubicEaseOut" />
<TransformOperationsTransition Property="RenderTransform" Duration="0:0:0.25" Easing="CubicEaseOut" />
</Transitions>
</Setter>
</Style>
<Style Selector="ComboBox.Outline /template/ Grid#PART_RootBorder">
<Setter Property="MinHeight" Value="52" />
</Style>
<Style
Selector="ComboBox.Outline:focus-within:not(ComboBox.Outline[SelectedIndex=-1]) /template/ Border#watermarkRoot,
ComboBox.Outline:focus-within /template/ Border#watermarkRoot,
ComboBox.Outline:not(ComboBox.Outline[SelectedIndex=-1]) /template/ Border#watermarkRoot">
<Setter Property="Margin" Value="14,-8,1,1" />
<Setter Property="RenderTransform" Value="scale(0.75)" />
</Style>
<Style Selector="ComboBox.Outline[SelectedIndex=-1]:not(:focus-within) /template/ Border#watermarkRoot">
<Setter Property="Margin" Value="10,14,1,1" />
<Setter Property="RenderTransform" Value="scale(1)" />
</Style>
<Style Selector="ComboBox.Outline">
<Setter Property="BorderThickness" Value="1" />
</Style>
<Style Selector="ComboBox.Outline:focus-within">
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}" />
<Setter Property="BorderThickness" Value="2" />
</Style>
<Design.PreviewWith>
<Border Padding="20" Width="360" Height="400">
<StackPanel VerticalAlignment="Center">
<ComboBox PlaceholderText="Test">
<ComboBox.Items>
<ComboBoxItem Content="Item 1" />
</ComboBox.Items>
</ComboBox>
<ComboBox Classes="Filled" PlaceholderText="Test">
<ComboBox.Items>
<ComboBoxItem Content="Item 1" />
</ComboBox.Items>
</ComboBox>
</StackPanel>
</Border>
</Design.PreviewWith>
</Styles>