![]() Example: If Age is >= 18 and IsAdmin is true then it should return red, if Age is < 18 and IsAdmin is true then would return green, etc. You have multiple properties (Age, IsAdmin, Name) in your ViewModel and according to these properties you want to change the TextColor of a Label. Have you ever wondered how to pass multiple parameters to a converter, or how to create properties in a converter to change the value based on them? If you want to know how to achieve it then keep reading :). Interested in sponsoring developer content? Message twitter for details.- If you don’t know what a converter is, I recommend you reading this article first. If you like what you see, don’t forget to follow me on twitter check out my GitHub, and subscribe to my blog to learn more mobile developer tips and tricks! – Two way binding triggers to show / hide the inner viewsĪnd once again, we get a nice little effect like this! – SelectedMessage toggles the ViewModel properties When the SelectedMessage we bound is changed, and not null, we toggle the ShowSenderName and the IsSentDateVisible to show/hide those views. Message.IsSentDateVisible = !message.IsSentDateVisible ![]() Message.ShowSenderName = !message.ShowSenderName Private void ToggleDetails(ChatMessageViewModel message) / Toggles the details of the given message. Public ChatMessageViewModel SelectedMessage Now lastly, let’s look at what’s going on in the ViewModel behind the ListView and how we are binding the SelectedItem. If you want to read more about that, check out this doc from Xamarin: We use the DataTemplateSelector to choose between the sent bubble and the received bubble, but that isn’t important. Now in order to update this, we need to bind our SelectedItem in our ListView. The important pieces to note are the IsVisible="" to show the date label or not. I even have some long press handlers from my LongPressedEffect that you can read about here: Xamarin.Tip – Xamarin.Forms Long Press Effect ![]() There is a lot going on in this cell (it’s a chat page after all, so it’s a feature rich cell). Here’s the XAML for the ViewCell shown in the gif above: This means that if we bind an update to show / hide certain controls on tap, those will show first, then we remeasure to make sure they fit. However, it’s important to note that this is so easy because of the order – calling the base.OnTapped() first allows for your click / select events to fire off before measuring the size. Override OnTapped and call ForceUpdateSize(). ![]() Public class ExpandingViewCell : ViewCell Let’s first create a new class called ExpandingViewCell: Force the ViewCell to remeasure its size to show the hidden bits. Handle updating that visibility on selection or tapģ. Bind visibility to the hidden parts of your cellĢ. There are 3 major parts to making a feature like this work:ġ. Here’s another helpful Xamarin tip to allow you to expand your ViewCells – for example when the user taps a ViewCell, expand it to reveal more information.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |