I recently did a blog post where I created a quick application that uses View Model. It looks like this:
I read a blog post by Phil Middlemiss called A Chrome and Glass Theme - Part 4 where he showed some really cool buttons. Well my example application could use a quick facelift, so I downloaded his code and opened up his project.
His project is Silverlight 3 and I am using Silverlight 4, but that doesn’t matter. I quickly saw the file I wanted, ChromeGlass.xaml.
I opened my SimpleRxExample project in Expression Blend and selected Add Existing Item… and I navigated to the location of the file in his project.
The file shows up in my project.
When I open the App.xaml file in my project I see that Blend has added the ChromeGlass.xaml file to the project as a Resource.
Now, I can right-click on an element such as the TextBox and select Edit Template –> Apply Resource –> TextBoxGlassyStyle, and give it a nice style.
When I run the project, it looks much nicer.
The new look of the Search button looks nice, but, I decide to download the buttons from Alan Beasley’s 10 Cool Buttons for Download in Expression Blend & Silverlight.
I can just open his project, and copy one of his buttons…
And paste it into my project.
I can drag the InvokeCommandAction behavior that is on the current Search button…
And drag it to the new button (and then delete the original Search button).
So now the application looks better, but I would like to make a Design change this time rather than simply a Style change. This is where the power of MVVM really shines. With MVVM, you can change the Design of an application without changing any code.
In the existing application, you search for a website, then select it from the dropdown. A hyperlink appears and you click on the Hyperlink to navigate to the website.
I am now ready to re-design the application. I remove the existing combo box and the Hyperlink.
I decide to create some sample data to make the design experience easier in Blend.
(Note: See this article on how to create sample design-time data)
I then create an Ellipse around the button.
I right-click on it in the Objects and Timeline window to convert it to a Layout Path.
This creates a [PathListBox] bound to the Ellipse.
I can click on the [PathListBox] to bind it to the data.
I bind it to the existing colWebsites collection.
(Note: To learn more about Path Layout see: http://electricbeach.org/?p=529)
I edit the template for the [PathListBox] …
… and change the layout to a Grid and place a Hyperlink in the Grid.
I then bind the Content of the Hyperlink to the name of the website and the NavigateUri to the website address.
I make a few adjustments to the settings for the [PathListBox] and the color of the Hyperlink, until it looks the way I want.
The final result reflects a total design change.
Now you type a search in the TextBox, click the Search button, and the sites appear around the Search button. You click on a site name to navigate to the site.
You can see a live example here:
You can download the code here:
Very cool Michael, & another good example of zero code designing. Just get rid of that silly green button! ha ha<br><br>Cheers for also putting up a working example for people to play with, it's well worth it!!!<br><br>Keep up the good work.<br><br>Alan