Skip to content

Commit 44f02d9

Browse files
committed
restore combo box scroll bars and virtualisation
1 parent 424e465 commit 44f02d9

File tree

5 files changed

+60
-107
lines changed

5 files changed

+60
-107
lines changed

MainDemo.Wpf/Domain/TextFieldsViewModel.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@
1010
namespace MaterialDesignColors.WpfExample.Domain
1111
{
1212
public class TextFieldsViewModel : INotifyPropertyChanged
13-
{
13+
{
14+
private readonly IList<int> _longListToTestComboVirtualization;
15+
1416
private string _name;
1517

18+
public TextFieldsViewModel()
19+
{
20+
_longListToTestComboVirtualization = new List<int>(Enumerable.Range(0, 1000));
21+
}
22+
1623
public string Name
1724
{
1825
get { return _name; }
@@ -23,13 +30,13 @@ public string Name
2330
}
2431
}
2532

33+
public IList<int> LongListToTestComboVirtualization => _longListToTestComboVirtualization;
34+
2635
public event PropertyChangedEventHandler PropertyChanged;
2736

2837
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
2938
{
30-
if (PropertyChanged != null)
31-
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
32-
//PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
39+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
3340
}
3441
}
3542
}

MainDemo.Wpf/TextFields.xaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,39 @@
130130
<ComboBoxItem>Windows</ComboBoxItem>
131131
</ComboBox>
132132

133+
<StackPanel Grid.Row="4" Grid.Column="4" Orientation="Horizontal">
134+
<ComboBox wpf:TextFieldAssist.Hint="Virtualisation"
135+
HorizontalAlignment="Left" Margin="16 0 0 0"
136+
ItemsSource="{Binding LongListToTestComboVirtualization}">
137+
<ComboBox.ItemsPanel>
138+
<ItemsPanelTemplate>
139+
<VirtualizingStackPanel />
140+
</ItemsPanelTemplate>
141+
</ComboBox.ItemsPanel>
142+
</ComboBox>
143+
<ComboBox wpf:TextFieldAssist.Hint="Virt (editable)"
144+
HorizontalAlignment="Left" Margin="16 0 0 0"
145+
IsEditable="True"
146+
ItemsSource="{Binding LongListToTestComboVirtualization}">
147+
<ComboBox.ItemsPanel>
148+
<ItemsPanelTemplate>
149+
<VirtualizingStackPanel />
150+
</ItemsPanelTemplate>
151+
</ComboBox.ItemsPanel>
152+
</ComboBox>
153+
<ComboBox wpf:TextFieldAssist.Hint="Virt (float hint)"
154+
HorizontalAlignment="Left" Margin="16 0 0 0"
155+
ItemsSource="{Binding LongListToTestComboVirtualization}"
156+
Style="{StaticResource MaterialDesignFloatingHintComboBox}">
157+
<ComboBox.ItemsPanel>
158+
<ItemsPanelTemplate>
159+
<VirtualizingStackPanel />
160+
</ItemsPanelTemplate>
161+
</ComboBox.ItemsPanel>
162+
</ComboBox>
163+
</StackPanel>
164+
165+
133166
<TextBox Grid.Row="4" Grid.Column="1" wpf:TextFieldAssist.Hint="Floating Hint" Style="{StaticResource MaterialDesignFloatingHintTextBox}" Text="Good stuff"
134167
Margin="0 8 0 8"/>
135168
<ComboBox Grid.Row="4" Grid.Column="3" wpf:TextFieldAssist.Hint="Search" IsEditable="True" Style="{StaticResource MaterialDesignFloatingHintComboBox}"

MaterialDesignThemes.Wpf/Converters/MathConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace MaterialDesignThemes.Wpf.Converters
1111
public enum MathOperation
1212
{
1313
Add,
14-
Sub,
14+
Subtract,
1515
Multiply,
1616
Divide
1717
}
@@ -34,7 +34,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
3434
return value1 / value2;
3535
case MathOperation.Multiply:
3636
return value1 * value2;
37-
case MathOperation.Sub:
37+
case MathOperation.Subtract:
3838
return value1 - value2;
3939
}
4040
}

MaterialDesignThemes.Wpf/Converters/MathMultipleConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public object Convert(object[] value, Type targetType, object parameter, Culture
2727
return value1 / value2;
2828
case MathOperation.Multiply:
2929
return value1 * value2;
30-
case MathOperation.Sub:
30+
case MathOperation.Subtract:
3131
return value1 - value2;
3232
}
3333
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml

Lines changed: 13 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,8 @@
99
</ResourceDictionary.MergedDictionaries>
1010

1111
<converters:TextFieldHintVisibilityConverter x:Key="TextFieldHintVisibilityConverter" />
12-
<converters:MathConverter Operation="Add" x:Key="MathAddConverter"/>
13-
<converters:BrushRoundConverter x:Key="BrushRoundConverter"/>
14-
<converters:MathMultipleConverter x:Key="MathMultipleConverter" Operation="Multiply"/>
15-
16-
<Storyboard x:Key="MaterialDesignComboBoxPopupAnimationExpand">
17-
<ThicknessAnimation Storyboard.TargetName="shadow"
18-
Storyboard.TargetProperty="Margin"
19-
From="16 0 16 0" To="0 0 0 0"
20-
AccelerationRatio="0.7" DecelerationRatio="0.3"
21-
Duration="0:0:0.3"/>
22-
<DoubleAnimation Storyboard.TargetName="AnimationScrollViewer"
23-
Storyboard.TargetProperty="Tag"
24-
From="0" To="1"
25-
AccelerationRatio="0.7" DecelerationRatio="0.3"
26-
Duration="0:0:0.5"/>
27-
<DoubleAnimation Storyboard.TargetName="PopupTemplateRootGrid"
28-
Storyboard.TargetProperty="Opacity"
29-
AccelerationRatio="0.7" DecelerationRatio="0.3"
30-
From="0" To="1" Duration="0:0:0.4"/>
31-
</Storyboard>
32-
33-
<Storyboard x:Key="MaterialDesignComboBoxPopupAnimationCollapse">
34-
<DoubleAnimation Storyboard.TargetName="PopupTemplateRootGrid"
35-
Storyboard.TargetProperty="Opacity"
36-
To="0" Duration="0:0:0"/>
37-
<DoubleAnimation Storyboard.TargetName="AnimationScrollViewer"
38-
Storyboard.TargetProperty="Tag"
39-
To="0" Duration="0:0:0"/>
40-
<ThicknessAnimation Storyboard.TargetName="shadow"
41-
Storyboard.TargetProperty="Margin"
42-
To="16 0 16 0" Duration="0:0:0"/>
43-
</Storyboard>
12+
<converters:MathConverter Operation="Add" x:Key="MathAddConverter"/>
13+
<converters:BrushRoundConverter x:Key="BrushRoundConverter"/>
4414

4515
<Style x:Key="FocusVisual">
4616
<Setter Property="Control.Template">
@@ -158,7 +128,7 @@
158128
</MultiTrigger>
159129
</ControlTemplate.Triggers>
160130
</ControlTemplate>
161-
131+
162132
<Style x:Key="MaterialDesignComboBoxItemStyle" TargetType="{x:Type ComboBoxItem}">
163133
<Setter Property="SnapsToDevicePixels" Value="True"/>
164134
<Setter Property="Padding" Value="16 8"/>
@@ -171,13 +141,10 @@
171141
<Setter Property="Template" Value="{StaticResource MaterialDesignComboBoxItemTemplate}"/>
172142
</Style>
173143

174-
175144
<Style x:Key="MaterialDesignComboBoxItemSelectedCollapsedStyle" TargetType="{x:Type ComboBoxItem}" BasedOn="{StaticResource MaterialDesignComboBoxItemStyle}">
176145
<Setter Property="Tag" Value="1.0"/>
177146
</Style>
178147

179-
180-
181148
<Style x:Key="MaterialDesignComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
182149
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
183150
<Setter Property="OverridesDefaultStyle" Value="true"/>
@@ -251,8 +218,6 @@
251218
Grid.ColumnSpan="2"
252219
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
253220
Style="{StaticResource MaterialDesignComboBoxToggleButton}"/>
254-
255-
256221
<TextBlock x:Name="Hint"
257222
Margin="{TemplateBinding Padding}"
258223
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
@@ -289,7 +254,7 @@
289254
VerticalOffset="-12"
290255
HorizontalOffset="-16"
291256
IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
292-
PopupAnimation="None"
257+
PopupAnimation="Fade"
293258
Placement="RelativePoint">
294259
<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}"
295260
x:Name="PopupTemplateRootGrid"
@@ -343,26 +308,9 @@
343308
SnapsToDevicePixels="True"/>
344309
</Grid>
345310
</Grid>
346-
<ScrollViewer Grid.Row="1"
347-
x:Name="AnimationScrollViewer"
348-
VerticalScrollBarVisibility="Hidden">
349-
<ScrollViewer.Tag>
350-
<system:Double>0.0</system:Double>
351-
</ScrollViewer.Tag>
352-
<ScrollViewer.Height>
353-
<MultiBinding Converter="{StaticResource MathMultipleConverter}">
354-
<Binding Path="ActualHeight" ElementName="DropDownScrollViewer"/>
355-
<Binding Path="Tag" RelativeSource="{RelativeSource Self}" />
356-
</MultiBinding>
357-
</ScrollViewer.Height>
358-
<ScrollViewer x:Name="DropDownScrollViewer">
359-
<StackPanel x:Name="ItemsPresenter"
360-
HorizontalAlignment="Stretch"
361-
IsItemsHost="True"
362-
KeyboardNavigation.DirectionalNavigation="Contained"
363-
UseLayoutRounding="True"
364-
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
365-
</ScrollViewer>
311+
<ScrollViewer Grid.Row="1">
312+
<ItemsPresenter x:Name="ItemsPresenter"
313+
KeyboardNavigation.DirectionalNavigation="Contained" />
366314
</ScrollViewer>
367315
<Rectangle Grid.Row="2"
368316
Height="8"
@@ -377,14 +325,6 @@
377325
<Setter TargetName="Underline" Property="Visibility" Value="Visible"/>
378326
<Setter TargetName="contentPresenter" Property="Visibility" Value="Collapsed"/>
379327
</Trigger>
380-
<Trigger Property="IsDropDownOpen" Value="True">
381-
<Trigger.EnterActions>
382-
<BeginStoryboard Storyboard="{DynamicResource MaterialDesignComboBoxPopupAnimationExpand}"/>
383-
</Trigger.EnterActions>
384-
<Trigger.ExitActions>
385-
<BeginStoryboard Storyboard="{DynamicResource MaterialDesignComboBoxPopupAnimationCollapse}"/>
386-
</Trigger.ExitActions>
387-
</Trigger>
388328
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
389329
<Setter Property="Margin" TargetName="shadow" Value="0"/>
390330
</Trigger>
@@ -481,15 +421,14 @@
481421
IsActive="{Binding ElementName=PART_EditableTextBox, Path=IsKeyboardFocused}"
482422
Visibility="Collapsed" />
483423

484-
485424
<Popup x:Name="PART_Popup"
486425
Grid.ColumnSpan="2"
487426
AllowsTransparency="true"
488427
Focusable="False"
489428
VerticalOffset="-15"
490429
HorizontalOffset="-16"
491430
IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
492-
PopupAnimation="None"
431+
PopupAnimation="Fade"
493432
Placement="RelativePoint">
494433
<Popup.RenderTransform>
495434
<ScaleTransform ScaleY="1"/>
@@ -560,26 +499,9 @@
560499
</Grid>
561500
</Grid>
562501
</Grid>
563-
<ScrollViewer Grid.Row="1"
564-
x:Name="AnimationScrollViewer"
565-
VerticalScrollBarVisibility="Hidden">
566-
<ScrollViewer.Tag>
567-
<system:Double>0.0</system:Double>
568-
</ScrollViewer.Tag>
569-
<ScrollViewer.Height>
570-
<MultiBinding Converter="{StaticResource MathMultipleConverter}">
571-
<Binding Path="ActualHeight" ElementName="DropDownScrollViewer"/>
572-
<Binding Path="Tag" RelativeSource="{RelativeSource Self}" />
573-
</MultiBinding>
574-
</ScrollViewer.Height>
575-
<ScrollViewer x:Name="DropDownScrollViewer">
576-
<StackPanel x:Name="ItemsPresenter"
577-
HorizontalAlignment="Stretch"
578-
IsItemsHost="True"
579-
KeyboardNavigation.DirectionalNavigation="Contained"
580-
UseLayoutRounding="True"
581-
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
582-
</ScrollViewer>
502+
<ScrollViewer Grid.Row="1">
503+
<ItemsPresenter x:Name="ItemsPresenter"
504+
KeyboardNavigation.DirectionalNavigation="Contained" />
583505
</ScrollViewer>
584506
<Rectangle Grid.Row="2"
585507
Height="8"
@@ -601,24 +523,15 @@
601523
<BeginStoryboard x:Name="MoveHintBackStoryboard_BeginStoryboard" Storyboard="{StaticResource MoveHintBackStoryboard}"/>
602524
</Trigger.ExitActions>
603525
</Trigger>
604-
526+
605527
<Trigger Property="IsEditable" Value="True">
606528
<Setter TargetName="GridContentCloneWrapper" Property="Margin" Value="16.5 25 16 4"/>
607529
<Setter TargetName="PART_Popup" Property="VerticalOffset" Value="-23"/>
608-
530+
609531
<Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/>
610532
<Setter TargetName="Underline" Property="Visibility" Value="Visible"/>
611533
<Setter TargetName="contentPresenter" Property="Visibility" Value="Collapsed"/>
612534
</Trigger>
613-
614-
<Trigger Property="IsDropDownOpen" Value="True">
615-
<Trigger.EnterActions>
616-
<BeginStoryboard Storyboard="{DynamicResource MaterialDesignComboBoxPopupAnimationExpand}"/>
617-
</Trigger.EnterActions>
618-
<Trigger.ExitActions>
619-
<BeginStoryboard Storyboard="{DynamicResource MaterialDesignComboBoxPopupAnimationCollapse}"/>
620-
</Trigger.ExitActions>
621-
</Trigger>
622535
<MultiTrigger>
623536
<MultiTrigger.Conditions>
624537
<Condition Property="wpf:TextFieldAssist.IsNullOrEmpty" Value="False" />

0 commit comments

Comments
 (0)