question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ListBoxItem.ItemContainerStyle resets MaterialDesign style even with BasedOn property set

See original GitHub issue

Setting ListBox item style in the following way

<ListBox.ItemContainerStyle>
    <Style BasedOn="{StaticResource {x:Type ListBoxItem}}" TargetType="{x:Type ListBoxItem}">
        ...
    </Style>
</ListBox.ItemContainerStyle>

…resets the actual ListBoxItem style to default (not material design).

However, the same exact approach works fine for TreeView and TreeViewItem.

I fixed it by setting BasedOn property to “{StaticResource MaterialDesignListBoxItem}”, but it’s suboptimal because it relies on a key that may or may not change.

Perhaps I’m doing something wrong?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Tyrrrzcommented, Oct 6, 2016

TargetType=“{x:Type MaterialDesignListBoxItem}” should be “{x:Type ListBoxItem}” I think. The original error is probably of the same cause as http://stackoverflow.com/a/7780980

1reaction
Tyrrrzcommented, Oct 6, 2016

Did you change the style to

<Style BasedOn="{StaticResource MaterialDesignListBoxItem}" TargetType="{x:Type ListBoxItem}">

?

Because that worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues with ListBoxItem selection when ItemContainerStyle ...
1 Answer 1. Sorted by: Reset to default. Highest score (default) ...
Read more >
ItemsControl.ItemContainerStyle Property
Gets or sets the Style that is applied to the container element generated ... is to set the ItemContainerStyle property of the ListBox...
Read more >
c# - WPF MVVM ColorLister with navigation
This tab will then be represented by its Icon property from inheriting from IPageViewModel . ColorList_Tab supports adding, editing, deleting ...
Read more >
WPF TabControl: Styling the TabItems
Learn how to style the TabItem elements of the WPF TabControl with this complete ... the background color of the tabs based on...
Read more >
Release notes
In Style, a new method, called RevertToDefault(), now sets the style of the cell, row or column back to its default value. In...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found