Wintellect Blogs

Supercharging Xamarin Forms with Custom Renderers, Part 4

Jeff Prosise

18 Apr , 2015  

If you’ve read the previous posts in this series, you’re aware that custom renderers are the keys that unlock the doors to advanced customizations in Xamarin Forms. In Part 1, I presented custom renderers for rounding the corners of and placing borders around Button controls. In Part 2, I used custom renderers to stylize the buttons in my Xamarin Forms RPN calculator. In Part 3, I showed how to use custom renderers to display wrapped, truncated text in Label controls. Now, in Part 4, I’m going to use custom renderers to do something completely different – something to customize a control’s behavior rather than its appearance, and in a way that could be useful to real-world apps.

Assume you’ve built a Xamarin Forms app with a page containing the following XAML:

<Grid Padding="32" RowSpacing="32" ColumnSpacing="32">
  <BoxView Grid.Row="0" Grid.Column="0" Color="#FFF25022" />
  <BoxView Grid.Row="0" Grid.Column="1" Color="#FF7FBA00" />
  <BoxView Grid.Row="1" Grid.Column="0" Color="#FF01A4EF" />
  <BoxView Grid.Row="1" Grid.Column="1" Color="#FFFFB901" />
</Grid>

Running the app produces this on Windows Phone, Android, and iOS, in that order:

SmartBoxView

Now suppose that when one of the colored rectangles is tapped, you want to highlight it by changing its color to, say, bright yellow.… Read more

, ,

Wintellect Blogs

Supercharging Xamarin Forms with Custom Renderers, Part 3

Jeff Prosise

7 Apr , 2015  

supercharger

One of the limitations of Xamarin Forms that frequently pains developers is the fact that the Label control supports text wrapping and text truncation, but it doesn’t support both at the same time. Specifically, Label’s LineBreakMode property can be set to LineBreakMode.WrapText to wrap text, or it can be set to LineBreakMode.TailTruncation to replace text at the end of a string with an ellipsis (…). But it can’t be set to both. Imagine you’re writing a Twitter client around a ListView control, and you want to show two or three lines of text for each tweet, with an ellipsis filling in for any text that won’t fit into the space provided. Sounds simple, but Xamarin Forms doesn’t offer a handy solution.

I ran into this problem when porting Contoso Cookbook to Xamarin Forms. On the app’s main page, I wanted to include a few lines of descriptive text under each recipe title. But the fact that Label doesn’t support wrapped, truncated text presented a problem. Rather than solve the problem then and risk taking away from the focus of the article, I decided to put it off until I published a series on custom renderers. This is Part 3 in that series, and it’s time to tackle wrapped, truncated text.… Read more

, , ,

Wintellect Blogs,WintellectNOW

Free 1.5 Hour Video: Writing Roslyn Analyzers and Code Fixes

John Robbins

7 Apr , 2015  

WNRoslyn

My deep abiding love of Roslyn continues! I just published a new video Writing Roslyn Analyzers and Code Fixes up at WintellectNOW: https://www.wintellectnow.com/Videos/Watch?videoId=writing-roslyn-analyzers-and-code-fixes. My goal was to take you from zero knowledge of Roslyn to writing a real world analyzer and code fix in 1.5 hours. This video covers everything from using the Syntax Visualizer to developing and testing analyzers and code fixes. Along the way I show how I solved some of the hard real world issues you’ll encounter.

Given that there’s not a lot of documentation on Roslyn I thought this video would help get folks up to speed as we approach the release date for Visual Studio 2015. I would love to hear any and all constructive criticisms you have on the video. What did I do right, what did I do wrong, and what else do you want to see. Sign up for a free WintellectNOW account and post to the discussion area under the video.

Please note that we reserve the right to move the video to subscription required in the future. Given how new Roslyn and VS 2015 are at the time of recording we thought it was good to get the info out now.Read more

,

Wintellect Blogs

Why Should You Attend Codestock?

Josh Carroll

7 Apr , 2015  

CodestockLogo

Codestock?

If you aren’t familiar with Codestock, then you should be, especially if you live anywhere in the southeast.

Codestock is a regional tech conference hosted in Knoxville, TN, and has been going on since 2007. It is consistently a great conference with incredible speakers and technical content at a very reasonable price.

Ok, so why should you attend?

Bigger And Better

In previous years, Codestock has been hosted at the UT Convention center, which only allowed for a maximum of 450 attendees. Last year, there were well over 100 people on the waiting list, so this year the conference is moving to a larger venue, The Knoxville Convention Center.

There is more than enough capacity for anyone who wants to come this year, and the Codestock organizers are expecting 800-900 attendees!

So if you want to come geek out with 800 of your fellow programmers, then you need to get a ticket.

Scott. Freaking. Hanselman.

This year, Scott Hanselman is going to be the keynote speaker. If you haven’t ever heard Scott speak before then you have missed a great chance to be educated and entertained at the same time.

Sure he works for “the man”, but if you haven’t noticed recently, Microsoft is cool again.… Read more

, ,

Wintellect Blogs

Supercharging Xamarin Forms with Custom Renderers, Part 2

Jeff Prosise

6 Apr , 2015  

image.png

In Part 1 of this series, I introduced custom renderers in Xamarin Forms and presented a pair of custom renderers – one for Android, and one for Windows Phone – that extended the Xamarin Forms Button control to honor the BorderRadius, BorderWidth, and BorderColor properties on all platforms. In Part 2, we’ll use what we learned to add some flair to the Xamarin Forms calculator app I presented a few weeks ago.

Here’s how the calculator looked in its original incarnation:

Now suppose you were handed UI requirements that called for the buttons to have rounded ends. Even if BorderRadius was supported on Windows Phone and Android, you’d have to write code to dynamically set the BorderRadius each time a button’s size changed since the buttons aren’t explicitly sized (they expand to fill the Grid cells that contain them) and they undergo a size change when the device orientation changes. Furthermore, assume that the calculator buttons need to have rounded ends, but that there might be other buttons in the app that need to have  the traditional square corners. How would you go about conforming to these requirements?

The answer, of course, is by writing custom renderers: this time for Windows Phone, Android, and iOS.… Read more

, , ,

Wintellect Blogs

Supercharging Xamarin Forms with Custom Renderers, Part 1

Jeff Prosise

3 Apr , 2015  

Palette

Xamarin Forms includes an assortment of “views,” more commonly known as controls, to help you build cross-platform UIs using XAML. Each control has a default appearance, and each control exposes properties that allow you to customize its appearance. But what if you’re handed a set of UI requirements that can’t be achieved using those properties? What if, for example, you need to round the corners on an Entry control or wrap and truncate text in a Label? (The Xamarin Forms Label control supports either but not both.) The Xamarin forums are full of such questions, and the answer is almost always “you need to write a custom renderer.”

If you’re going to use Xamarin Forms in real-world projects, you’re going to need custom renderers. Custom renderers let you customize the logic that “renders” native controls from Xamarin Forms controls. Knowing how to write custom renderers – and when to use them – is one of the skills that separates expert Xamarin Forms developers from the rest of the pack.

The subject of custom renderers is a multifaceted one. Some renderers require little effort to write. Others are much more difficult and require intimate knowledge of the platforms on which they run.… Read more

, , ,

Wintellect Blogs

Analyzing Control Flow with Roslyn

John Robbins

30 Mar , 2015  

shutterstock_207985381

The other day my co-worker Jeffrey Richter and I were discussing my latest infatuation, Roslyn analyzers. As we bounced around a few ideas one came to the forefront; every catch block should throw. This is not a hard and fast rule, but eating an exception, especially accidentally, has caused more bugs in .NET than we all care to count. My mind started spinning thinking that I want to see if I can automate checking for eaten exceptions in a Roslyn analyzer.

At first glance, the idea seems pretty easy. Look for the catch blocks and look to see if there are any throws, returns, or, goto statements. (Realizing that you can use a goto in a catch block made me involuntarily shudder.) Anyway, sketching through a quick algorithm of going about analyzing the syntax nodes made me realize there was going to be nothing quick about it. This was going to be a lot of work, especially when you really start thinking about all the ramifications. While I welcomed the challenge, I thought I better look deeper at the Roslyn API to see what it offers. Fortunately for everyone, there’s a super nice control flow analysis engine built right into Roslyn.… Read more

,

Wintellect Blogs

Learn Roslyn at the Microsoft MVP Virtual Conference

John Robbins

23 Mar , 2015  

MVP15_VCon

Mark your calendars for May 14-15, 2015 for the free 2015 Microsoft MVP Virtual Conference. This is a Microsoft sponsored conference where Microsoft Valuable Professionals (MVPs) will be presenting five different tracks for world wide consumption: IT Pro, Developer, Consumer, LATAM (Spanish), and Brazil (Portuguese). Obviously, I’ll be in the Developer track, but I’m really excited about the multiple language tracks. Making development and IT more welcoming to non-English speakers is awesome.

I’ll be presenting the following session. Go register today.

Roslyn for Normal Developers: It’s Not Just for Compiler Geeks!

You have no doubt heard about Roslyn, the new C# and VB.NET compilers in Visual Studio 2015, and you are probably wondering what they mean to you as a normal developer especially since you don’t have a PhD in Compilerology. In this demo only session you’ll see that no matter the type of .NET development you are doing, Roslyn will quickly become one of your favorite tools. You’ll learn how to leverage Roslyn analyzers and code fixers to fix problems in your team’s code as its being written. You’ve dreamed about having super smart editors that find the bugs before you check in and Roslyn is the answer!

After this session, you’ll know how to develop, test, and deploy your own Roslyn analyzers and code fixers to ensure your team is coding correctly and using your architecture the way you want all by leveraging the actual compiler.… Read more

,

Wintellect Blogs

More Wintellect.Analyzers and Some Lessons Learned Writing Roslyn Analyzers

John Robbins

20 Mar , 2015  

shutterstock_196881245

Over the last few months I have been having a wonderful time developing Roslyn analyzers and code fixes. You can find all the Wintellect.Analyzers code at Wintellect’s GitHub page. If you would like to include these analyzers in your own Visual Studio 2015 CTP 6 project, install the NuGet package by executing the following in Visual Studio’s package manager console window:

  1. Install-Package Wintellect.Analyzers Prerelease

Now that I’m getting more fluent in analyzers and code fixes I wanted to share some of the things I’ve learned to save you some time when you start doing your own in the future. First I’ll go over some of the new analyzers I’ve written. Next I’ll turn to the question of using analyzers and code fixes as NuGet packages vs. a Visual Studio VSIX. Finally, I’ll jump into some of the development aspects of analyzer and code fix development where I’ve had issues. Obviously, in that section, I’m assuming you know something about Roslyn and analyzer development. If this is all new to you Alex Turner’s two part series in MSDN Magazine gives you a solid understanding quickly: Part 1, Part 2.

Since I first blogged about Wintellect.Analyzers I’ve added another eight rules to the mix.… Read more

,

Wintellect Blogs

Xamarin Forms, Contoso Cookbook, and Azure: Three Great Tastes that Taste Great Together

Jeff Prosise

13 Mar , 2015  

reeses

My previous post introduced a Xamarin Forms version of Contoso Cookbook that runs on Windows Phone, Android, and iOS. For the benefit of developers learning Xamarin Forms – especially those already versed in Microsoft XAML – it introduced the basics of navigating between pages in a multipage app with NavigationPage and creating tabbed pages with TabbedPage. It also introduced ListView as a means for binding to collections and data templates for specifying how items in those collections should be rendered.

That version of Contoso Cookbook relied on local data – one JSON file plus a collection of images – embedded in the Portable Class Library (PCL). In real life, data such as this typically comes from the cloud. Therefore, I thought it might be useful to modify Contoso Cookbook to pull data from Microsoft Azure. That’s the subject of this article.

The revised version of Contoso Cookbook doesn’t look any different on the outside: It still uses a TabbedPage to present a list of recipes and recipe groups, and it still uses NavigationPage to navigate to a ContentPage showing recipe details when a recipe is tapped. You may notice that it takes longer for the recipes and recipe groups to appear, however, because the data is no longer loaded locally.… Read more

, , ,