Is there a way to change a ListView visually based on a bound property?

EasyGoingPatEasyGoingPat GBMember ✭✭✭

I have a ListView that shows a list of devices. Tapping one of these initiates connection, which can take some time. I have an IsBusy property in the view-model, which becomes true while a connection is in progress. I have bound the ListView.IsEnabled property to this and it successfully blocks more taps on the ListView while a connection is in progress.

I would like to give some visual indication to show that the ListView cannot be tapped but there doesn't seem to be any way to do this. I have tried triggers on the ListView and on the visual elements in the ListView (e.g. a Label.TextColor property). Nothing seems to work.

Does anyone know how to do this?

Best Answers

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think you can visualize a popup that show a waiting icon.

    Something like https://github.com/aritchie/userdialogs

  • EasyGoingPatEasyGoingPat GBMember ✭✭✭
    edited November 2018

    @AlessandroCaliaro

    Mmm ... that's an interesting idea. I'm not fond of dragging in a load of stuff (e.g. MvvMCross) that I'm not currently using but I do already inject basic dialogs from the UI down into the platform-independent code, so a small extension to this (i.e. a busy-dialog or similar) might be a good way to go. Since dialogs are modal, it would also solve the problem of locking the user out of the other controls.

    One foreseeable problem is that eventually I will have to implement connection attempts to multiple devices simultaneously. When I implement that, I really will need the ability to disable individual ListView entries and ideally show them as disabled.

    • Patrick
  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    change a ListView visually based on a bound property

    If you just want to change properties of the ListView based on a property that sounds like a perfect situation for a DataTrigger.

    If a piece of data changes then it triggers something to change.
    If IsBusy becomes true... then trigger the background to become Blue.
    if CountOfUsers become 4... then trigger the background to become Red.
    If DogsName becomes Max... then trigger the CatImage.IsVisible to become false.

    and so on.

  • EasyGoingPatEasyGoingPat GBMember ✭✭✭

    @ClintStLaurent

    Thanks for the reply.

    I have tried a DataTrigger but it had no effect. I read something somewhere about needing to swap out the whole style for the ListView to get a runtime change in appearance but I haven't had time to experiment with this yet. (It also sounds like way too much work for such a simple thing.)

    • Patrick
  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @EasyGoingPat said:
    I have tried a DataTrigger but it had no effect.

    Then something wasn't right. I use this very often it it does work.

    I read something somewhere about needing to swap out the whole style for the ListView to get a runtime change in appearance

    Shouldn't have to. That sounds like someone had their binding fouled up.
    I will mention this though... There is a bug when it comes to styles in Xamarin: Always list the <style> tag last on your element. Otherwise other attributes won't override attributes in the <style>. I first reported it through bugzilla 2-3 years ago. Still waiting for it to get some attention.

  • EasyGoingPatEasyGoingPat GBMember ✭✭✭

    @ClintStLaurent said:

    I have tried a DataTrigger but it had no effect.

    Then something wasn't right. I use this very often it it does work.

    That's very interesting! Any chance of a XAML snippet, showing how you handle it? No problem if it would be too much trouble to get one together.

    ~ Patrick

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Yeah. I can find some time this afternoon to do it in my sandbox app so its not part of my protected company app code.

  • EasyGoingPatEasyGoingPat GBMember ✭✭✭

    @ClintStLaurent

    Totally understand if you are short on time but any chance of a snippet of code to show how to do this?

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Sorry.. First day back at a PC since eye surgery. Let me see what I can do. Thanks for the reminder because I had totally forgotten about this.

  • NMackayNMackay GBInsider, University mod
    edited December 2018

    @ClintStLaurent said:

    @ClintStLaurent said:
    Sorry.. First day back at a PC since eye surgery. Let me see what I can do. Thanks for the reminder because I had totally forgotten about this.

    Finished example of what this will look like

    Default look

    DataTrigger look

    The ListView is triggering off the IsBusy property. How you change that is up to your app. I'm just toggling it with a button wired to a command.

    Wiring up the ListView XAML

    The really nifty part of this is we are only triggering for a given condition. When that condition becomes not what we are triggering on, the values automatically revert to their default values. In other words, we only have to trigger for IsBusy as true and what values we want then. We do not also have to set up values for false - it will revert on its own.

    Nice guide....you should start a blog :smile:

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @NMackay said:
    Nice guide....you should start a blog :smile:

    What an idea... I wish I had thought of that.

  • NMackayNMackay GBInsider, University mod

    @ClintStLaurent said:

    @NMackay said:
    Nice guide....you should start a blog :smile:

    What an idea... I wish I had thought of that.

    It was my suggestion, I want my cut of the ad revenue :D

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @NMackay said:

    @ClintStLaurent said:

    @NMackay said:
    Nice guide....you should start a blog :smile:

    What an idea... I wish I had thought of that.

    It was my suggestion, I want my cut of the ad revenue :D

    Ok... Lets see... nuthin'... over nuthin'... times zilch... divided by nada... is... Zero US dollars. I think that's 4 Euros.
    Hey... Weren't you supposed to write an article to go on that blog?

  • NMackayNMackay GBInsider, University mod
    edited December 2018

    @ClintStLaurent said:

    @NMackay said:

    @ClintStLaurent said:

    @NMackay said:
    Nice guide....you should start a blog :smile:

    What an idea... I wish I had thought of that.

    It was my suggestion, I want my cut of the ad revenue :D

    Ok... Lets see... nuthin'... over nuthin'... times zilch... divided by nada... is... Zero US dollars. I think that's 4 Euros.
    Hey... Weren't you supposed to write an article to go on that blog?

    I was, this year hasn't gone entirely to plan...catch up directly with you.

  • EasyGoingPatEasyGoingPat GBMember ✭✭✭

    @ClintStLaurent

    Totally understand if you are short on time but any chance of a snippet of code to show how to do this?

  • EasyGoingPatEasyGoingPat GBMember ✭✭✭
    edited December 2018

    @ClintStLaurent
    @NMackay

    Thanks so much for that!

    Annoyingly, I've lost the original code I was playing with (probably binned in a fit of frustration!) but I'm sure it was close to that. I think maybe I had the triggers in the ListView.ItemTemplate instead of the ListView itself.

    Anyway, working adequately now. Thanks again!

    I will eventually have to solve the problem of disabling individual items in the ListView and styling them to indicate this but that's for another day.

    ( @ClintStLaurent - Hope the eye(s) get better quickly!)

    • Patrick
  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @EasyGoingPat said:
    @ClintStLaurent

    Totally understand if you are short on time but any chance of a snippet of code to show how to do this?

    Did you mean to ask this again at 0309am? Seems I already posted code example. maybe the forum just had a hiccup.

  • EasyGoingPatEasyGoingPat GBMember ✭✭✭

    @ClintStLaurent

    I haven't knowingly re-posted, Clint. In fact, not noticed anything strange at all at my end. I do get confused by all these buttons in front of me, though. They all have letters and numbers on them but there's no instructions!

    • Patrick
Sign In or Register to comment.