Xamarin: Xamarin Podcast: MVVM Frameworks with James Montemagno

Deciding which patterns to use when developing your app can be difficult, which is why James Montemagno and I discuss MVVM frameworks and our approach to developing cross-platform apps with as much code reuse as possible on this week’s episode of the Xamarin Podcast. Subscribe or Download Today Knowing the latest in .NET, C#, and Xamarin […]

The post Xamarin Podcast: MVVM Frameworks with James Montemagno appeared first on Xamarin Blog.

Daniel Cazzulino: How to disable Xamarin Forms XAML Intellisense in VS 2015

Straight answer first just in case you’re in a hurry:

  1. Delete C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDEExtensionsXamarinXamarin[VERSION]static.14.pkgdef
  2. Run devenv /updateconfiguration

In addition to this manual workaround, we’ll post an updated Xamarin.Forms pre-release nuget package that won’t provide the design assemblies to XAML and will stop the crash from happening. But that won’t turn off XAML intellisense, which will be all red (as it is without the 1.5-pre nuget).

Now the long answer if you’re interested 🙂

XML vs XAML intellisense

For Visual Studio 2012 and 2013, we provide Xamarin.Forms intellisense by extending the core text editor using the same extensibility APIs you use to extend any other text-based editor. Besides being able to use some XML-editor provided APIs to access the current document, we basically have to keep track of keystrokes, completion sessions, dismissal on Esc and so on. In addition to also discovering types and members available for completion.

In Visual Studio 2015, the XAML editor became extensible so we could take advantage of all the work already done by Microsoft for WPF by just providing some metadata via the NuGet package itself, and registering our Xamarin.Forms namespace to opt-in XAML intellisense instead. This was the result of close collaboration with the XAML team, since XF is pretty much the first non-WPF flavor of XAML around.

In addition to being a solid editor for many years, opting in for XAML intellisense also means we will get all new features they add to WPF for free. In particular around the data binding expressions and markup extensions.

Unfortunately, when we enabled XAML intellisense for our XML namespace, we triggered a bug that causes the XAML editor to crash VS. Microsoft is aware of the issue, has identified the issue and is actively looking for ways to ship this to users. Worst case, it should be available in VS2015 Update 1, november-ish.

How to get XML intellisense back

We will soon release an update to the current stable release that will re-enable the XML-based intellisense for Xamarin.Forms. Stay tunned on the Release Blog for news.

Xamarin: Xamarin.UITest Reaches 1.0 Release

Mobile app users form a lasting impression of your app within the first minute that can make them long-term, loyal users who encourage their peers to use the app, or they could have a bad experience, encountering a bug or slow load times, that immediately make them abandon the app and find an alternative. We […]

The post Xamarin.UITest Reaches 1.0 Release appeared first on Xamarin Blog.

Keith Rome: Understanding native image sizing in Xamarin Forms apps

This post is about probably my least favorite part of mobile app development – figuring out and assembling all of the various images needed to build an application and publish it into the stores. Each platform has its own requirements for this, and often you will need to provide multiple resolution versions within each platform in order to handle varying pixel density ratios. Xamarin supports all of the necessary resource types of course, but it is still up to us as developers to include the right images in our projects.

For very simply apps this isn’t quite as big of a problem – but it becomes a huge headache for medium-size and large-size apps. To help make my life easier, I like to use a spreadsheet to identify all of the images needed along with the final image resolutions and preferred file names. This works great because I can give this spreadsheet to the UX designer and have them provide all of the assets – already sized and named appropriately so that I can just drop them right into my project. So let’s cover all of the various image types that an app might need – including both the minimum required images as well as optional ones.… Read more

Keith Rome: Understanding Native Image Sizing in Xamarin Forms Apps

This post is about probably my least favorite part of mobile app development – figuring out and assembling all of the various images needed to build an application and publish it into the stores. Each platform has its own requirements for this, and often you will need to provide multiple resolution versions within each platform in order to handle varying pixel density ratios. Xamarin supports all of the necessary resource types of course, but it is still up to us as developers to include the right images in our projects.

For very simply apps this isn’t quite as big of a problem – but it becomes a huge headache for medium-size and large-size apps. To help make my life easier, I like to use a spreadsheet to identify all of the images needed along with the final image resolutions and preferred file names. This works great because I can give this spreadsheet to the UX designer and have them provide all of the assets – already sized and named appropriately so that I can just drop them right into my project. So let’s cover all of the various image types that an app might need – including both the minimum required images as well as optional ones.… Read more

Xamarin: Visualize Your Data with Charts, Graphs, and Xamarin.Forms

There’s even more to Xamarin.Forms than the 40+ pages, layouts, and controls that make it fast and easy to build native apps while sharing 90%+ code across platforms. With Xamarin.Forms’ custom renderer capability, you can extend Xamarin.Forms to gain access to every native control in iOS, Android, and Windows and even create your own custom […]

The post Visualize Your Data with Charts, Graphs, and Xamarin.Forms appeared first on Xamarin Blog.

Alec Tucker: Xamarin.Forms SearchBar with Mvvm

Wow – it’s been a long time since my last post. I’ve been very busy with something that I hope to chat about before too long…

In the meantime, here are some thoughts on using the Xamarin.Forms SearchBar control with Mvvm.
Firstly, there’s a great, simple explanation of the control itself here: https://www.syntaxismyui.com/xamarin-forms-searchbar-recipe/
This shows how to get up and running without Mvvm, applying a search filter form the TextChanged event of the SearchBar. When you put this into an Mvvm structured app there are a couple of gotchas to look out for. You can bind the Text property of the SearchBar to an Mvvm compatible string property in your ViewModel, and the setter replaces the TextChanged event on the above link, like this:

    <SearchBar Text={Binding SearchText}

               SearchCommand={Binding SearchCommand}

    />

Where your SearchText definition in your associated view model would look something like this:

        private string _searchText;

        public string SearchText

        {

            get { return _searchText; }

            set { if (_searchText != value) { _searchText = value; RaisePropertyChanged(() => SearchText); } }

        }

You can now set up the ObservableCollection property in your viewmodel which you have bound your list to looks something like this:

        public ObservableCollection<YourEntity> YourList

        {

            get

            {

                ObservableCollection<YourEntity> theCollection = new ObservableCollection<YourEntity>();

                if (_yourList != null)

                {

                    List<YourEntity> entities = (from e in _yourList

                        where e.dealerDisplayName.Contains(_searchText)

                        select e).ToList<YourEntity>();

                    if (entities != null && entities.Any())

                    {

                        theCollection = new ObservableCollection<YourEntity>(entities);

                    }

                }

                return theCollection;

            }

        }

(This assumes that you have other code to populate _yourList in the first place, by reading from a DB or perhaps calling a web service.)
The SearchBar also supports command binding (as you can see from the xaml above), so we can define our search command like this:

        #region Command and associated methods for SearchCommand

        private Xamarin.Forms.Command _searchCommand;

        public System.Windows.Input.ICommand SearchCommand

        {

            get

            {

                _searchCommand = _searchCommand ?? new Xamarin.Forms.Command(DoSearchCommand, CanExecuteSearchCommand);

                return _searchCommand;

            }

        }

        private void DoSearchCommand()

        {

            // Refresh the list, which will automatically apply the search text

            RaisePropertyChanged(() => YourList);

        }

        private bool CanExecuteSearchCommand()

        {

            return true;

        }

        #endregion

Now let’s embellish our property a little to get it to execute the command each time the text is changed. (This is effectively the Mvvm equivalent of the TextChanged event in the blog post referenced above.)

        public string SearchText

        {

            get { return _searchText; }

            set

            {

                if (_searchText != value)

                {

                    _searchText = value;

                    RaisePropertyChanged(() => SearchText);

                    // Perform the search

                    if (SearchCommand.CanExecute(null))

                    {

                        SearchCommand.Execute(null);

                    }

                }

            }

        }

All well and good. However, there are two gotchas here. This code, as it stands, will fail. The problem is that the first time in, _searchText is not an empty string – it’s null. This upsets our Linq statement. We can remedy this by changing:

        private string _searchText;

to:

        private string _searchText = string.Empty;

First time in things now work fine. You should also be able to apply filtering to your list and watch it in action. However, there’s one more gotcha waiting in the wings. The SearchBar comes with a built in ‘Cancel’ button, which you can use to clear your search text. Your users will expect this to remove all filtering and display the entire list again. However, clicking the ‘Cancel’ button does not set the Text property of the SearchBar to an empty string – you guessed it, it sets it to null. This upsets our Linq statement all over again.
We can remedy this by changing the setter of our property slightly, to ensure that if an attempt is made to set it to null, it will simply set it to an empty string instead. We’ll change this:

_searchText = value ;

to this:

_searchText = value ?? string.Empty;

It should now be happy again, and ready to roll.

Xamarin: Pearson is at the Top of the Class with Xamarin

Pearson is the world’s leading learning company, with 40,000 employees in over 80 countries helping people of all ages make measurable educational progress. Recently they introduced the Pearson System of Courses (PSOC), a vertically and horizontally aligned system that supports learning, motivation, and engagement through a coherent curriculum covering math from K-11 and English Language […]

The post Pearson is at the Top of the Class with Xamarin appeared first on Xamarin Blog.