Answer the question
In order to leave comments, you need to log in
What causes styles to disappear in WPF?
I wrote a custom style for the listview, connected it as a resourcedictionary, everything worked well. Then I set a couple of properties to the elements through listview.ItemContainerStyle and the styles set earlier disappear. What have I done wrong?
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="IsSelected" Value="{Binding IsChecked}"/>
<Setter Property="IsEnabled" Value="{Binding IsEnabled}"></Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
Answer the question
In order to leave comments, you need to log in
Once an ItemTemplate or ItemContainerStyle is overridden, the old styles are completely overwritten accordingly. Unspecified values are overwritten with default values.
The declaration from the code example is equivalent to the code:
var view = new ListView();
view.ItemTemplate = new DataTemplate();
view.ItemContainerStyle = new Style() { ... };
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question