Advanced Databinding Part 4 – Binding .

In this post we will examine one of the aspects of advanced databinding that many people find confusing. Binding . (that is, Binding dot). However, it is surprisingly easy to explain.

Binding . allows you to access the entire binding context.

This is best understood with an example

<StackLayout BindingContext="{x:Static sys:DateTime.Now}"
                 HorizontalOptions="Center"
                 VerticalOptions="Center">

            <Label Text="{Binding Year, StringFormat='The year is {0}'}" />
            <Label Text="{Binding StringFormat='The month is {0:MMMM}'}" />
            <Label Text="{Binding Day, StringFormat='The day is {0}'}" />
            <Label Text="{Binding StringFormat='The time is {0:T}'}" />
            <Label Text="{Binding ., StringFormat='The full date is {0}'}" />
            <Label Text="{Binding}" />

        </StackLayout>

Here the stacklayout sets its BindingContext to DateTime.Now. That will allow us to bind to properties of the DateTime object that has the current local time. The first few lines are straight forward, we bind to properties of the DateTime object. For example,

Continue reading
Posted in Essentials | Leave a comment

C# 10 & Documentation: Bill Wagner

Bill Wagner joins us once again, this time to talk about C# 10 and the evolving Microsoft. documentation.

Check back here for links but I just couldn’t wait to publish this.

Posted in Essentials | Tagged | Leave a comment

Advanced Databinding Part 3 – Null or Missing Values

You want to bind to a collection of values and display each in turn, but it is possible that some of the objects in the list have null properties, or some properties are missing altogether.

You can handle this with value converters, but there is a better (easier to write, easier to understand when reviewing) way.

In your Xaml, if you suspect a value may be null, you can makr it TargetNullValue and give it a string to display

TargetNullValue='Age unknown'

Similarly, if the value may be missing you can provide a default value,

FallbackValue='No School Found'

In this posting we’ll show how to use both.

Continue reading
Posted in Essentials | Leave a comment

Advanced Databinding: Part 0 – BASICS

In the ugly old days, if you had data that you wanted to display you would put the data into a variable and then write some code to copy that data to a control on your page. If the data changed, your code had to update the display. If you had a list of data, you had a bit of code to write to get each item in the list displayed in turn.

Xamarin.Forms provides Databinding to do all that work for you. Essentially you say “here’s my data and I want it in this UI element over here. If the data changes, update the display for me.” Even better you can say “here is a collection of objects, and here is how I want you to display properties from each one in turn and if something is added to or taken from the collection, adjust the list accordingly.

“Databinding” is well named: you bind your data to a control, and as the data changes, that change is reflected in the control.

Continue reading
Posted in Essentials | Tagged , , | Leave a comment

Advanced Databinding Part 2: Converters

En Español

There are times when you need to bind to a source but the source is not in the right format or otherwise needs to be manipulated.

For example, suppose, as we’ll show below, that you have a text entry and a button, but you only want the button enabled as long as there are one or more characters in the text entry, and of course if there is no text entered you want to disable button.

You could bind the button to a boolean property in your View Model and bind the text to another property and then on text changed you could test to see if there is text in the entry control and update the button.  Yuck.

Continue reading
Posted in Essentials | Leave a comment

Advanced Data Binding Part 1

This is the first in a series on advanced data binding. In this series we will look at: using value converters with binding, relative binding, the {Binding .} and {Binding self} constructs, and more.

We hope to release one of these every week or two. 

Getting Started

We will be posting Part 0 shortly.

Samples

For each topic we discuss, we will provide a simple sample (as simple as possible but no simpler) which we’ll put up on Github and we’ll provide the URL in the blog post. We will walk through that sample to eliminate any confusion and to drive home what we’ve said about the topic.

Some of the samples we’ll make up for this series, others we’ll steal from the Microsoft documents. Which reminds me, why would you read this instead of the official documents? The answer, for me, is that the Microsoft documents are very thorough, but sometimes that can be overwhelming. Most important, however is that triangulating from multiple sources can help zero in on a full understanding.

Topic #1: Paths

The use of the path keyword is a good, intermediate place to start. It can be used in a number of ways. The most frequent is either to point to a property of an object held in a resource, or to point to a property of a property.

 

Continue reading
Posted in Advanced Data Binding, Essentials, Xamarin.Forms | Leave a comment

The Miracle of IQueryAttributable

This knocked me out. Let’s say you have a value in one view model, and when you navigate to another page you want that value in the new page’s view model. Enter IQueryAttributable. (tough to say, even tougher to spell)

I have created a simple example. We’re going to start with an out of the box Xamarin.Forms project. As part of that we’ll get an AboutPage. At the bottom of the about page I’m going to add a button:

<Button Text="ShowId" Command="{Binding ShowIdCommand}" />

Nothing surprising here. Let’s follow that ShowIdCommand. For that we turn to the associated view model (also out of the box)

Continue reading
Posted in Essentials | 1 Comment

Lance McCarthy

Lance McCarthy talking about Maui, VS2022, community contributions and much more.

Referenced sites and source:

Resource 1 – CommonHelpers

That is the CommonHelpers NuGet package I was referring to. It not only is a good helper in a .NET project, but you can also look at it’s GitHub Actions to see how to automatically built, test and publish  to NuGet.

Resource 2 – DevOpsExamples

That repo shows you how to build WPFASP.NET CoreWinFormsConsoleXamarin.Forms, .NET MAUIAngularReact and Vue projects in GitHub ActionsAzure DevOpsGitLab CI and AppCenter (see the build status badges here).

The workflows can be found here https://github.com/LanceMcCarthy/DevOpsExamples/tree/main/.github/workflows

Resource 3 – MediaFileManager a real-world CI-CD example for WPF

This repo is for MediaFileManager, one of my real-world WPF apps that is published to the Microsoft Store. It shows you how to use GitHub Actions to automatically build MSIX packages and publish to the Microsoft Store.

Not only does it build and upload to the Store, but I also show how to build an msixbundle with an appinstaller file that gets uploaded to Azure Blob Storage so you can host your own mini-Microsoft Store for your non-Store users. Check out the mini-store page here Media File Manager (windows.net)

Resource 4 (bonus) – AI Powered Toilet Flusher for my Cat

I built a full system that uses AI, SignalR, Windows IoT, and Xamarin.Forms to automatically flush the human toilet when my cat uses it. You can see the companion blog post here Using Windows IoT, SignalR, Azure Custom Vision and Xamarin Forms to Flush a Toilet – DVLUP

Posted in .Net 6, Essentials | Tagged | Leave a comment

Visual Studio 2022!!

Mads Kristensen talks about all the goodness in Visual Studio 2022

Posted in Essentials | Tagged | Comments Off on Visual Studio 2022!!

A Dozen Utilities I Use Every Day

Here are 12 utilities I use every day. They are in no particular order. I spend most of my day programming in Visual Studio 2019.

#0 – Resharper. I’m so ambivalent about this add on for Visual Studio. On the one hand it has some fantastic features for a serious programmer. On the other hand, it is a beast and can significantly slow both loading VS and building your app. I’ve loaded it and removed it a number of times. On balance, it is a killer utility.

Continue reading
Posted in Essentials | Comments Off on A Dozen Utilities I Use Every Day

Get Git in 45 Minutes

Presentation to the St. Pete’s user group

Note, discussion starts 9 minutes in.

 

Posted in Essentials | Comments Off on Get Git in 45 Minutes

Mads Torgersen On C# 10

Mads comes back on show 200 (!) to talk about all things C# 10, which will be released November 2021.

Posted in C#, C# 10, Essentials, Languages, Podcast | Tagged | Comments Off on Mads Torgersen On C# 10