WPF Listview пустой текст

pip uninstall pip будет работать & nbsp;

6
задан Alexander Zwitbaum 19 June 2009 в 17:03
поделиться

2 ответа

This XAML will do something similar, it has a visible ListView showing a list and a hidden message and switches visibility when the list is empty using a trigger.

The code below will work with any IList or ICollection but the same technique can be used with any data source, like always, if you want the display to update when you add or remove items you need to use an ObservableCollection or similar.

The ContentPresenter is there because you can only use triggers inside a template or a style, so we put our controls inside a DataTemplate and use the ContentPresenter to show it.

If you want the message to appear inside the ListView than all you have to do is remove the Setter that hides the ListView and add some margin to the TextBlock to position it where the first item in the ListVIew should be.

<ContentPresenter Content="{Binding}">
    <ContentPresenter.ContentTemplate>
        <DataTemplate>
            <Grid>
                <ListView Name="list" ItemsSource="{Binding MyList}"/>
                <TextBlock Name="empty" Text="No items found" Visibility="Collapsed"/>
            </Grid>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding MyList.Count}" Value="0">
                    <Setter TargetName="list" Property="Visibility" Value="Collapsed"/>
                    <Setter TargetName="empty" Property="Visibility" Value="Visible"/>
                </DataTrigger>                        
            </DataTemplate.Triggers>
        </DataTemplate>
    </ContentPresenter.ContentTemplate>
</ContentPresenter>
12
ответ дан 10 December 2019 в 00:43
поделиться

Привязать его к DataSource + Property, которое возвращает нужный текст? Слот в фиктивном объекте, строковое представление которого является желаемым текстом ..

-2
ответ дан 10 December 2019 в 00:43
поделиться
Другие вопросы по тегам:

Похожие вопросы: