Wintellect Blogs

Linking Property Change Notifications in Xamarin Forms (or WPF/Silverlight)

Keith Rome

17 Oct , 2015  

I’d like to share a really awesome bit of code that I’ve been using in my XAML applications for a while now… there are many frameworks and examples out there, but I’ve not yet seen anyone else using this exact technique before…

MVVM in XAML UI Applications

If you are building app UIs using XAML, then you are more likely than not also using the MVVM design pattern. The general idea is that your code which handles application logic, business rules, etc. gets placed into ViewModel classes, and all visual widgets/controls get placed into XAML views. Typically we would have one View per ViewModel, but that’s not a requirement at all (more like a generalized observation), and in fact there are some situations where we might want to have multiple Views for the same ViewModel (or break a complex ViewModel into multiple parts while still connecting to a single View). The ViewModels are supposed to capable of standing alone, and we use data bindings and command bindings to connect the two. This way, we can unit test our ViewModels thoroughly, and (sometimes) allow UX designers to dictate the XAML layout directly.

That’s all fairly normal and typical.

As we dig a little more deeply into the mechanisms of data binding, we learn that part of the “magic” is achieved by way of the INotifyPropertyChanged interface (which includes only one thing – an event named PropertyChanged).… Read more

, , , ,

Wintellect Blogs

Model-View-ViewModel (MVVM) Explained

Jeremy Likness

24 Apr , 2014  

The purpose of this post is to provide an introduction to the Model-View-ViewModel (MVVM) pattern. While I’ve participated in lots of discussions online about MVVM, it occurred to me that beginners who are learning the pattern have very little to go on and a lot of conflicting resources to wade through in order to try to implement it in their own code. I am not trying to introduce dogma but wanted to pull together key concepts in a single post to make it easy and straightforward to understand the value of the pattern and how it can be implemented. MVVM is really far simpler than people make it out to be.

Why Even Care About MVVM?

Why should you, as a developer, even care about the Model-View-ViewModel pattern? There are a number of benefits this pattern brings to both WPF and Silverlight development. Before you go on, ask yourself:

  • Do you need to share a project with a designer, and have the flexibility for design work and development work to happen near-simultaneously?
  • Do you require thorough unit testing for your solutions?
  • Is it important for you to have reusable components, both within and across projects in your organization?
  • Would you like more flexibility to change your user interface without having to refactor other logic in the code base?
Read more

,

Wintellect Blogs

Silverlight: Where Do We Go From Here?

Jeremy Likness

24 Apr , 2014  

Silverlight made its debut in 2006 with the confusing acronym WPF/E (that’s Windows Presentation Foundation, Everywhere). Indeed the original dream was that a slimmed down version of the .NET Framework could run as a plugin in any browser (including smart phones) and enable developers to wield their weapons of XAML, data-binding, and C# to write line of business apps that would run everywhere. Although it took a few versions to mature, in May of 2011 version 5.0 was released with the features most requested by enterprise users. That was also the year I wrapped up my book about building business applications with Silverlight, titled Designing Silverlight Business Applications (Addison-Wesley, 2012).

In the forward of that book I discussed how the refusal of certain vendors to include the plugin on their smartphones didn’t necessarily mean the demise of Silverlight, but would relegate it to the domain of rich enterprise business applications. HTML5 was still f

ragmented and JavaScript was a very difficult language to scale across large teams and maintain on enterprise projects. Later that year when Microsoft announced their plans for the upcoming Windows 8 operating system, developers around the world took notice of two things: the heavy emphasis on apps written with HTML5 and JavaScript, and the lack of any mention of Silverlight.… Read more

, , , , ,

Wintellect Blogs

Showing the Onscreen Keyboard in Silverlight OOB Applications

John Garland

11 Apr , 2014  

Update – 4/10/2014  Wow!  Quite a lot has happened since I originally posted this.  Certainly one of the biggest changes is the diminished role that Silverlight now plays in both enterprise and consumer applications.  However, I’ve noticed that this particular blog post is still getting some attention, so I figured I’d try to provide some direction that Silverlight developers might be looking for or otherwise be interested in.

  • First and foremost, if you’re looking for resources to help you evaluate or actually execute a move from Silverlight to an alternate technology, check out the Wintellect Silverlight Migration Strategies page which includes Noel Stieglitz’s whitepaper that discusses various options and strategies that are available to you.  I’d also suggest checking out Microsoft’s free e-book “.NET Technology Guide for Business Applications.” 
  • If you’re interested in concepts related to touch for the new Windows Store Apps, check out the book that I co-authored with Jeremy Likness “Programming the Windows Runtime by Example”.  In particular, Chapter 13 (Devices) deals with concepts related to touch interaction.

 

One of the “interesting” things about Silverlight apps running on Windows is that on touch/tablet systems, textboxes in Silverlight do not display a popup button to use for bringing up the Windows onscreen keyboard when they have focus, whereas native applications do.… Read more

Wintellect Blogs

Handling Extremely Large Data Sets in Silverlight

Jeremy Likness

8 Apr , 2014  

While writing Chapter 14 of my book, Designing Silverlight Business Applications: Best Practices for Using Silverlight Effectively in the Enterprise (Microsoft .NET Development Series) I focused on an area that is quite common with line of business applications: extremely large data sets. In the example I generated almost 1,000,000 contact rows to illustrate how they would be managed by the Silverlight client. Like many software problems, there are many solutions; here is an excerpt of the three I demonstrated in the book.

All of these solutions use the Entity Framework for data access. How that data access is projected to the client is illustrated bythree different patterns: OData (the straight services, not the checkbox on the WCF RIA Services tab), WCF RIA Services, and using the MVVM pattern. To simplify the examples I’m only focused on reads here. Writes do add a layer of complexity and change tracking, but I argue that the problem to solve there is not how to manage a large data set because anything the user actually interacts with is going to be a smaller order of magnitude.

If you are looking to upgrade your existing Silverlight application, our free whitepaper covers common approaches we’ve encountered to ensure you can still handle those large data sets using modern technology stacks.… Read more

,

Wintellect Blogs

Hosting HTML in Silverlight (not Out of Browser)

Jeremy Likness

8 Apr , 2014  

Some Silverlight projects may require that you render HTML content – perhaps a non-Silverlight control or web page. Unfortunately unless the project runs Out of Browser (OOB) the WebBrowser control isn’t an option. What can you do?

While there is no easy solution to truly embed HTML inside of the Silverlight rendering engine, it is possible to render the HTML using the browser into a DIV element that is overlaid on your Silverlight application. In fact, because the rendering engine is powerful enough to provide you with all of the sizing events and triggers you need, you can create a very convincing experience displaying HTML in your application – even from the browser.

Note: are you looking to modernize your Silverlight application? Check out our free whitepaper about Silverlight modernization.

To illustrate this in action, we’ll build a sort of “Silverlight browser” that allows you to navigate to any web page. In reality, we’ll load the URL into an IFRAME that lives inside a DIV. What will be important to note is that the DIV automatically moves and resizes when you resize the application, as if it were a part the application itself!

Silverlight Browser

In fact, before we jump into the code, why not click here to check it out yourself?… Read more

Wintellect Blogs

Angular: The Modern HTML5 Answer to Silverlight’s MVVM

Jeremy Likness

30 Mar , 2014  

First, let me say that I realize Silverlight in no way “owns” the Model-View-View Model pattern. I’ve written on this extensively in my article “MVVM Explained.” However, I believe it gained the most public exposure through various implementations on that platform and this is what led to its adoption on the web. In fact, you might think its strange to think that Microsoft could have possibly influenced the sacred land of open source JavaScript, but if you trace the history of view models you’ll find not only did they segue from WinForms to XAML technologies, but they initially made their way to the web via early data-binding implementations like KnockoutJS.

I have to admit I was extremely skeptical when I first saw the concept of creating a view model in a browser. As much as I loved XAML’s data-binding it felt like a square peg and a round hole. What really concerned me the most was the extra work involved to take an ordinary JavaScript object (JSON) and turn it into a view model using things like ko.observable. This has been vastly improved and simplified, and as I began to adopt the strategy for the web I realized quickly it made sense.… Read more

, , , , , , , ,

Wintellect Blogs

Advanced Silverlight Applications using the Managed Extensibility Framework

Jeremy Likness

15 Apr , 2013  

This week I had the pleasure of attending my first CodeStock event in Knoxville, TN. Let me start by saying it was an amazing event. I give many thanks to the attendees, for keeping it a strong and thriving community, the sponsors (including my company, Wintellect), the speakers, and of course the organizers. You can learn more about the event at the page I linked to above. I highly recommend it – great venue and setup, and fantastic people. I connected and made friends with many people in both the .NET and programming community in general.

X-Fit Sample Application

For my talk on advanced applications in Silverlight using the Managed Extensibility Framework, I built a sample application called “the X-Fit Sample Application.” I often hear complaints that demos and blog posts focus on one screen and a button. I wanted to build something with more depth than that, and used that application for my presentation.

What does it demonstrate?

  • Region management
  • De-coupling of views and view models
  • Dynamic loading of XAP files on-demand
  • OOB (Out-of-Browser)
  • Recognizing out of browser and behaving differently
  • Loading a plugin from the file system
  • Messaging using MEF
  • “Tracing” using Debug
  • Debugging MEF parts (imports and exports)
  • …and plenty more

You can click here to view: X-Fit Sample Application

The source code and slide shows from my deck are both available at this link:

Deck and source

To use the application, jump into it and fill out the information.… Read more

,

Wintellect Blogs

Koch Snowflakes on Windows 8 with XAML

Jeremy Likness

26 Nov , 2012  

A few years back I wrote a little program that would generate Koch snowflakes in Silverlight. After brisk walk in the cold weather today, I decided it was time to port it over to Windows 8, more just to see how easy it would be. It turns out it only took about 5 minutes to have the program up and run

ning. I made a few tweaks, and it works. I spent some more time just changing how the snowflakes are updated. It is definitely far from perfect (there is an occasional unhandled exception I haven’t debugged and it pegs the CPU) but it’s still a fun little project to run and see.

The Koch curve is simple. You start with a line segment, break it into thirds, and extend the middle third into a triangle. You then repeat the process with the outer line segments recursively. This image depicts the process:

Working backwards, the implementation for the Windows Store app starts with a helper method that takes a set of points and turns them into a path so we can render the snowflake on the XAML surface:

private static Path CreatePath(IReadOnlyList<Point> points)
{
   
var segments = new PathSegmentCollection();

   
foreach (var point in points.Skip(1))
    {
        segments.Add(
           
new LineSegment
                {
                    Point = point
                });
    }

   
var pathGeometry = new PathGeometry();

   
// pull the segments into the geometry
    pathGeometry.Figures.Add(
       
new PathFigure
            {
                IsClosed =
true,
                StartPoint = points[0],
                Segments = segments
            });

   
return new Path { Data = pathGeometry };
}

The points turn into segments then are collapsed into a closed path.… Read more

,

Wintellect Blogs

Designing Silverlight Business Applications Officially Released

Jeremy Likness

5 Apr , 2012  

 

slbookcover

In June of 2011 I started the journey of writing a Silverlight book. The Silverlight team was about to release version 5 with an incredible set of new features that would revolutionize how it can be used in the enterprise. I knew there were already a number of books available to use a reference for fundamentals and controls, so I wanted to dig deeper and hit the topics I was challenged with in my job as a consultant as well as those questions that continually seem to surface on blogs and forums. I began with an introduction that analyzed client technologies available at the time, especially focusing on how HTML5 was evolving but not yet mature. The focus of the book is my “sweet spot” as I have been developing Silverlight applications for the enterprise since it’s version 3 release in 2008.

No one could have realized just how much change would take place over the following year. Silverlight 5 was released but without a roadmap for version 6 and Windows 8 was announced. Fortunately it was soon discovered that Windows 8 provides a path to build applications using C# and XAML, has full support for running Silverlight 5, and through the Portable Class Library even provides a path to create code that can be used to target both present state and future state applications.… Read more

,