Skip to content

Commit c9202cb

Browse files
authored
Allow for setting ListBoxItemAssist.ShowSelection on the root control (#2455)
This allows for it to propagate down.
1 parent c0217b2 commit c9202cb

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

MainDemo.Wpf/Lists.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@
6969
UniqueKey="list_4"
7070
Grid.Column="1">
7171
<Grid>
72-
<ListBox>
72+
<ListBox materialDesign:ListBoxItemAssist.ShowSelection="False">
73+
<!--
74+
Alternatively you can specify ListBoxItemAssist.ShowSelection on individual items
7375
<ListBox.ItemContainerStyle>
7476
<Style TargetType="ListBoxItem" BasedOn="{StaticResource MaterialDesignListBoxItem}">
7577
<Setter Property="materialDesign:ListBoxItemAssist.ShowSelection" Value="False"/>
7678
</Style>
7779
</ListBox.ItemContainerStyle>
80+
-->
7881
<TextBlock Text="Listbox"/>
7982
<TextBlock Text="Without"/>
8083
<TextBlock Text="Selection"/>

MaterialDesignThemes.UITests/WPF/ListBoxes/ListBoxTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,25 @@ public async Task ScrollBarAssist_ButtonsVisibility_HidesButtonsOnMinimalistStyl
130130

131131
recorder.Success();
132132
}
133+
134+
[Fact]
135+
public async Task OnListBoxAssist_WithShowSelectDisabled_SelectionIsDisabled()
136+
{
137+
await using var recorder = new TestRecorder(App);
138+
var listBox = await LoadXaml<ListBox>($@"
139+
<ListBox materialDesign:ListBoxItemAssist.ShowSelection=""False"">
140+
<ListBoxItem>Mercury</ListBoxItem>
141+
<ListBoxItem>Venus</ListBoxItem>
142+
<ListBoxItem>Earth</ListBoxItem>
143+
<ListBoxItem>Pluto</ListBoxItem>
144+
</ListBox>
145+
");
146+
var earth = await listBox.GetElement<ListBoxItem>("/ListBoxItem[2]");
147+
await earth.LeftClick();
148+
var selectedBorder = await earth.GetElement<Border>("SelectedBorder");
149+
await Wait.For(async () => Assert.False(await selectedBorder.GetIsVisible()));
150+
151+
recorder.Success();
152+
}
133153
}
134154
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ListBox.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@
223223
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
224224
<Setter Property="Padding" Value="8"/>
225225
<Setter Property="SnapsToDevicePixels" Value="True"/>
226-
<Setter Property="wpf:ListBoxItemAssist.ShowSelection" Value="True"/>
226+
<Setter Property="wpf:ListBoxItemAssist.ShowSelection" Value="{Binding Path=(wpf:ListBoxItemAssist.ShowSelection), RelativeSource={RelativeSource AncestorType=ListBox}}"/>
227227
<Setter Property="Template">
228228
<Setter.Value>
229229
<ControlTemplate TargetType="{x:Type ListBoxItem}">

0 commit comments

Comments
 (0)