简体   繁体   中英

How to check if the listview contains nothing in c# UWP

Question : Good morning all. I have three checkboxes, and I wish to disable the three checkboxes if the condition of SelectedRoomListView is empty is met.

I have researched thoroughly online but to no avail. Have tried the following method.

Method:

            if(SelectedRoomListView == null)
            {
                addBed.IsEnabled = false;
                addBreakfast.IsEnabled = false;
                addWifi.IsEnabled = false;
            }

The code did not take effect when the listview is empty. Absolute beginner in Coding especially C#. Thank you all! :)

Try this:

        if (SelectedRoomListView.Items.Count == 0)
        {
            addBed.IsEnabled = false;
            addBreakfast.IsEnabled = false;
            addWifi.IsEnabled = false;
        }

I guess your ListView isn't really null and has been initialized. However, you want to check if its empty, therefore you want to check if it has Items. So if the number of items it contains equals 0, there are none - and the ListView is empty.

In case it didn't work, please share more code so we will get the context :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM