I bind the items to ListView, and I found if there is no items in listview the height will be 2. So I just want to make the height to 0 if the ListView is Empty. Thank you.
Asked
Active
Viewed 130 times
0
-
2Welcome to stackoverflow. Please try to be more detailed when asking a question: add the relevant code parts - probably the XAML in your case - and explain what did you try to solve the issue. Those details will help others better understand your problem and thus you have a better chance of getting a relevant answer. – qqbenq Jan 05 '21 at 11:13
-
But you might check out [this question](https://stackoverflow.com/questions/8154213/how-to-define-empty-datatemplate-for-the-itemscontrol-based-controls-like-listvi) to see a solution that uses a custom template when an ItemsControl is empty. – qqbenq Jan 05 '21 at 11:17
-
consider adding some code – Denis Schaf Jan 05 '21 at 13:18
1 Answers
1
You can use a data trigger to achive this:
<ListView ItemsSource="{Binding MySource}" Height="100" Width="100" Background="HotPink">
<ListView.Style>
<Style TargetType="ListView">
<Style.Triggers>
<DataTrigger Binding="{Binding MySource.Count}" Value="0">
<Setter Property="Height" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.Style>
</ListView>

Denis Schaf
- 2,478
- 1
- 8
- 17