Silverlight, WPF, ASP.NET

Silverlight LOB Forms

Wednesday, November 19, 2008 7:12:32 AM (Eastern Standard Time, UTC-05:00)

I’ve been thinking a lot lately on how different types of layout controls can be used make the tools and the framework do the heavy lifting for us in our Silverlight Development. Karl Shifflett recently posted an example creating a custom WPF control to make it easier to layout a data input screen and I decided to build out a Silverlight version.

The control extends an ItemsControl to use a custom container that provides a text label and layout for input controls.

image 

The result is a custom control that allows me to add input controls such as TextBoxes and CheckBoxes and get labels and much of the styling for free. Silverlight’s DataBinding capabilities allow me to set a DataContext for the FormControl, and then simply specify an individual binding for each field.

<TextBox Zelt:FormItem.LabelContent="First Name" Text="{Binding FirstName}" Width="250"/>
<TextBox Zelt:FormItem.LabelContent="Last Name" Text="{Binding LastName}" Width="250"/>

Utilizing this type of markup allows for a lot of potential in tool support. I’m sure that Karl plans to support this type of content in his XAML Power Toys add-in.

I’ve got a few additions before I share out the code, but I’d welcome any feedback on this approach.

Posted in  | Comments [0] 


Great .NET Conference Opportunity

Monday, November 17, 2008 6:29:42 PM (Eastern Standard Time, UTC-05:00)

Go to the DevTeach site

 

In early December Montreal is hosting an exciting developer conference covering a wide range of topics from some of our industry's leading presenters. The 3 day conference is packed with information in 136 sessions. Pre and Post conference sessions are also available to increase your learning potential at the event. Attendees will also receive over $1000 in free software!

The fun starts Tuesday December 2nd with a key by Ted Neward. See you there!!!

http://www.devteach.com

Posted in  |  |   | Comments [0] 


PDC Content Comes to the Carolinas!

Wednesday, November 05, 2008 9:34:45 PM (Eastern Standard Time, UTC-05:00)

Did you miss PDC? Want to see some of the latest content relating to Cloud Computing, Silverlight 2, and the future directions of ASP.NET 4? Links are below for your FREE invite!

Introducing the MSDN Southern Fried Roadshow:

 

The MSDN Southern Fried Roadshow is a  ¾ day, free developer event with a southern flair where you will learn about some of the latest developments in Microsoft technologies. For this edition we will cover a broad range of the latest Microsoft Technologies:

· Take a tour of Microsoft’s cloud computing platform and the services that make it easy to give your applications the most compelling experiences and features.  Explore the journey a developer takes, from writing a service to launching that service in the cloud. Learn about the cloud services that enable developers to easily create or extend their applications and services.

· Microsoft Silverlight provides a powerful platform for building the next generation of rich interactive applications on the Internet. In this session, we take a look at the programming model and tools that developers and designers can leverage to build these true next-generation experiences for consumers and business, and demonstrate building a rich interactive application (RIA) using Silverlight and Microsoft .NET.

· ASP.NET is evolving a very rapid pace, come explore all the latest features of ASP.Net such as Dynamic Data, MVC, and even take a sneak peak at the upcoming features in ASP.NET 4.0!  We’ll look at some new features such as taking control of your Control IDs, using the DynamicImage control, and ViewState management options.   We’ll spend plenty of time talking about MVC and creating applications based on this framework, so if you’re wondering how to leverage MVC in your web applications, this talk is for you!

 

12/2/2008 -- Charleston

12/3/2008 – Wilmington

12/4/2008 - Raleigh

12/5/2008 - Charlotte

Posted in  |   | Comments [0] 


Silverlight 2 Timeline Panel

Sunday, October 19, 2008 9:43:08 PM (Eastern Daylight Time, UTC-04:00)

A while back I posted on creating a custom layout panel in WPF that could arrange items based on an assigned date property to create a timeline view. Working through the creation of this panel taught me a great deal about how powerful the layout system was in WPF, and now how that power and flexibility extends into Silverlight 2.

The Silverlight 2 layout system is largely based on the use of panels, which includes the Canvas, Grid, and Stack Panel. Silverlight 2 includes a base Panel that you are able to derive from and override it’s default layout behavior. In addition to the basic functionality that comes with Panel, it provides two methods that you can easily override to create your own behavior. MeasureOverride and ArrangeOverride are the heart of the layout, determining the the position of elements. It’s essentially a to phase process where MeasureOverride examines the child elements of the panel to see what size they would “like to be”. The ArrangeOverride the tells the children the size and location they “are going to be”, based on whatever calculations you specify.

This example shows how using a custom attached property to specify an event date for any child element placed on the panel that ArrangeOverride can then use to position them.

 

Silverlight TimeLinePanel - Windows History Timeline

This view showing the history of Windows version release dates is created using this XAML markup:

 <local:TimelinePanel Width="800" Height="280" 
                             StartDate="1/1/1984" StopDate="12/12/2010" 
                             Background="LightGray">
       <TextBlock local:TimelinePanel.EventDate="11/1/1985">Windows 1.0</TextBlock>
       <TextBlock local:TimelinePanel.EventDate="12/1/1987">Windows 2.0</TextBlock>
       <TextBlock local:TimelinePanel.EventDate="5/1/1990">Windows 3.0</TextBlock>
       <TextBlock local:TimelinePanel.EventDate="4/1/1992">Windows 3.1</TextBlock>
       <TextBlock local:TimelinePanel.EventDate="5/30/1995">Windows NT 3.51</TextBlock>
       <TextBlock local:TimelinePanel.EventDate="8/24/1995" >Windows 95</TextBlock>
       <TextBlock local:TimelinePanel.EventDate="6/1/1996">Windows NT 4</TextBlock>
       <TextBlock local:TimelinePanel.EventDate="6/1/1998">Windows 98</TextBlock>
       <TextBlock local:TimelinePanel.EventDate="2/1/2000">Windows 2000</TextBlock>
       <TextBlock local:TimelinePanel.EventDate="7/1/2000">Windows Me</TextBlock>
       <TextBlock local:TimelinePanel.EventDate="10/1/2001">Windows XP</TextBlock>
       <TextBlock local:TimelinePanel.EventDate="1/1/2007">Windows Vista</TextBlock>
</local:TimelinePanel>

 

As you can see from the XAML markup, a Start and Stop date are specified for the date range that the panel will display. Each child element, in this case TextBlock’s have an EventDate property specified. It should be noted that the TextBlock itself has no concept of an event date coded into it. EventDate is an Attached Property, a dependency property that can be “attached” to any element.

“An attached property is a concept defined by XAML. An attached property is intended to be used as a type of global property that is settable on any object element in XAML. In Silverlight version 2, attached properties are typically defined as a specialized form of dependency property that does not have the conventional property wrapper in the object's CLR object model.”

MSDN has more details on attached properties in Silverlight 2 online.

In the ArrangeOverride code I simply scale the date based on the EventDate’s relative position to the StartDate and StopDate of the TimeLinePanel giving me a horizontal position. For the vertical position I track the position of the previous element and if it overlaps I place it below, creating a cascading effect for overlapping elements.

protected override Size ArrangeOverride(Size finalSize)
        {
            double lastX = 0;
            double lastY = 0;
            foreach (UIElement element in this.Children)
            {
                DateTime eventDate = (DateTime)element.GetValue(EventDateProperty);
                double pos = ScaleDate(eventDate);
                double left = finalSize.Width * pos;
                double top = (double)element.GetValue(VerticalOffsetProperty);
                if (double.IsNaN(top) == true)
                    top = 0.00;

                double width = element.DesiredSize.Width;
                double height = element.DesiredSize.Height;
                if (lastX + width > left)
                {
                    top = lastY + 20 + (double)element.GetValue(VerticalOffsetProperty);
                }
                else
                {
                    top = 0 + (double)element.GetValue(VerticalOffsetProperty);
                }
                element.Arrange(new Rect(left, top, width, height));
                lastX = left;
                lastY = top;
            }
            return finalSize;
        }

The use of custom panels for layout in Silverlight 2 creates a world of exciting possibilities, giving developers and designers an incredibly flexible set of tools. With the ability for panels to be reused within other controls such as the ListBox (Shown in my previous Solar System ListBox Demo) advanced user experiences become much easier to create. By placing the TimeLinePanel into the ItemsPanelTemplate of ListBox and attaching the EventDate to the ListBoxItem, I now have all of the functionality of a ListBox, with the visual display of my TimeLinePanel.

<ListBox>
      <ListBox.ItemsPanel>
              <ItemsPanelTemplate>
                  <local:TimelinePanel Width="800" Height="280" 
                         StartDate="1/1/1984" StopDate="12/12/2010" Background="LightGray">
                  </local:TimelinePanel>
              </ItemsPanelTemplate>
      </ListBox.ItemsPanel>
      <ListBoxItem local:TimelinePanel.EventDate="11/1/1985"><TextBlock Text="Windows 1.0" /></ListBoxItem>
      <ListBoxItem local:TimelinePanel.EventDate="12/1/1987"><TextBlock Text="Windows 2.0" /></ListBoxItem>
      <ListBoxItem local:TimelinePanel.EventDate="5/1/1990"><TextBlock Text="Windows 3.0" /></ListBoxItem>
      <ListBoxItem local:TimelinePanel.EventDate="4/1/1992"><TextBlock Text="Windows 3.1" /></ListBoxItem>
      <ListBoxItem local:TimelinePanel.EventDate="5/30/1995"><TextBlock Text="Windows NT 3.51" /></ListBoxItem>
      <ListBoxItem local:TimelinePanel.EventDate="8/24/1995"><TextBlock Text="Windows 95" /></ListBoxItem>
      <ListBoxItem local:TimelinePanel.EventDate="6/1/1996"><TextBlock Text="Windows NT 4" /></ListBoxItem>
      <ListBoxItem local:TimelinePanel.EventDate="6/1/1998"><TextBlock Text="Windows 98" /></ListBoxItem>
      <ListBoxItem local:TimelinePanel.EventDate="2/1/2000"><TextBlock Text="Windows 2000" /></ListBoxItem>
      <ListBoxItem local:TimelinePanel.EventDate="7/1/2000"><TextBlock Text="Windows Me" /></ListBoxItem>
      <ListBoxItem local:TimelinePanel.EventDate="10/1/2001"><TextBlock Text="Windows XP" /></ListBoxItem>
      <ListBoxItem local:TimelinePanel.EventDate="1/1/2007"><TextBlock Text="Windows Vista" /></ListBoxItem>
</ListBox>

Silverlight TimeLinePanel replacing default ListBoxItemsPanel 

Live demo of TimeLinePanel

Silverlight 2 TimeLinePanel Demo Source Code

 

Technorati Tags: , ,

Posted in  | Comments [2] 


Silverlight 2 Controls - Styles and Templates

Sunday, October 19, 2008 12:33:27 AM (Eastern Daylight Time, UTC-04:00)

With the release of Silverlight 2, I’ve been working on updating a number of my existing demos as well as building a number of new ones for upcoming presentations. One of my favorite features in Silverlight 2 (And WPF) is the ability to change the visuals of a control through styles and templates, without impacting the control logic. The demo that really drove this home to me was created by Beatriz Costa. Her post on The power of Styles and Templates in WPF showed a simple yet effective way to have the visuals of controls can be altered, leaving the logic of the control intact to do all of the expected ListBox stuff. (Fire events, provide a selected item, respond to keyboard up/down). This flexibility and separation of control visuals from control logic is one of the key elements of WPF, and now Silverlight.

I started with a some basic controls on a page including a databound ListBox and a UserControl containing some TextBlocks.

image 

After applying the styles and templates the application visuals are transformed into something much more interesting, while maintaining the complete functionality of a ListBox, while appearing as a Solar System ListBox.

            <ListBox x:Name="listbox1" Height="600" Width="1000"                 
                SelectionChanged="listbox1_SelectionChanged" 
                Template="{StaticResource ListBoxTemp}"
                ItemContainerStyle="{StaticResource DefaultListBoxItemStyle}"      
                ItemTemplate="{StaticResource ListBoxItemContainerPlanet}">
            </ListBox>

image  

In order to take things a step further, I also replaced the ItemsPanel of the ListBox with a custom carousel panel. The original CarouselPanel code I started with is by Jamie Rodriguez and found here.

                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>                    
                        <local:CarouselPanel x:Name="planets" 
                            Width="800" Height="600" Grid.Row="0"  
                            Speed="0.03" UseMousePosition="False"  
                            ScalePerspective=".2" />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>

The result is an interactive interface with the planets orbiting around the screen, while still maintaining the full functionality of the underlying ListBox below.

image

Live Demo HERE

Source Code: (Soon)

Control Customization Documentation Resources:

Styling and Templating Overview
Control Styles and Templates
Creating a Templatable Control

** And yes… I know the ongoing debate about Pluto being a “dwarf planet” and not a “real” planet any more… deal with it.

Posted in  | Comments [0] 


Raleigh Code Camp 2008 – Fall Edition

Saturday, October 18, 2008 11:17:44 PM (Eastern Daylight Time, UTC-04:00)

Registration will soon be opening for the Raleigh Code Camp 2008 Fall Edition (RCC2008FE for short). Keep an eye on www.codecamp.org and www.trinug.org to register for the event in the near future. It’s going to be a crazy couple of weeks for me here so I wanted to get this reminder out early.I was able to sneak a peak at the session list and it’s action packed with a variety of great topics covering pretty much every aspect of .Net development.

We’re also very excited to have Karl Shifflett back in the Carolinas as our keynote speaker. Karl who has recently taken a position with Microsoft in Redmond will be covering some WPF and Silverlight related topics including his recently released XAML Power Toys and Ocean.

If you have never attended a Code Camp event before, I strongly encourage you to plan to attend. The events pack a variety of topics presented by a wide range of speakers, both local and from afar. In addition to the presenters, the events attract an energetic group of your peers interested in learning and expanding their .NET related skills. This is a great way to cram much of the value of an industry conference into a local, 1 day, free to attend event. With some uncertainty  in the economy, this is a great way to get some free training, network with your peers, and sharpen your skills.

With Code Camp falling just a couple of weeks after the Microsoft PDC conference, I can pretty much guarantee that at least a few of the sessions will contain some valuable details on things to come.

Posted in  | Comments [0] 


Silverlight 2 Released!

Thursday, October 16, 2008 7:18:44 AM (Eastern Daylight Time, UTC-04:00)

As you’ve likely heard, Microsoft has released Silverlight 2. I was fortunate to have been involved along the way and getting to interact with many members of the various teams involved. I want to start by offering a gigantic congratulations to everybody involved. You guys did a great job moving things along with such speed an innovation! Having had a chance to see a glimpse of what went on behind the scenes I have a tremendous level of respect and admiration for that teams of great people that made this release possible It is truly an amazing  and passionate group, and every member should be proud. It seems like just yesterday that “Silverlight” was unveiled as the proper name or WPF/E. I can’t wait to see the future innovation.

Some of the key highlights of this release include:

•.NET Framework support with a rich base class library. This is a compatible subset of the full .NET Framework.

•Powerful built-in controls. These include DataGrid, ListBox, Slider, ScrollViewer, Calendar controls and more.

•Advanced skinning and templating support. This makes it easy to customize the look and feel of an application.

•Deep zoom. This enables unparalleled interactivity and navigation of ultrahigh resolution imagery.

•Comprehensive networking support. Out-of-the-box support allows calling REST, WS*/SOAP, POX, RSS and standard HTTP services, enabling users to create applications that easily integrate with existing back-end systems.

•Expanded .NET Framework language support. Unlike other runtimes, Silverlight 2 supports a variety of programming languages, including Visual Basic, C#, JavaScript, IronPython and IronRuby, making it easier for developers already familiar with one of these languages to repurpose their existing skill sets.

•Advanced content protection. This now includes Silverlight DRM, powered by PlayReady, offering robust content protection for connected Silverlight experiences.

•Improved server scalability and expanded advertiser support. This includes new streaming and progressive download capabilities, superior search engine optimization techniques, and next-generation in-stream advertising support.

•Cross-platform and cross-browser support. This includes support for Mac, Windows and Linux in Firefox, Safari and Windows Internet Explorer.

For me personally, Silverlight 2 represents a great opportunity to leverage my existing skill investment in .NET and extend beyond the server and desktop  into a richer browser experience. I’ve been working on updating the code for a number of new posts that I will be sharing in the days ahead, as well as updating some of my previous samples.

Posted in  | Comments [0] 


Silverlight 2 RC0 Available for Developers

Friday, September 26, 2008 6:19:51 PM (Eastern Daylight Time, UTC-04:00)

Microsoft has released Release Candidate 0 of Silverlight 2 today. This release is intended for developers to allow them to test there application and bring it up to speed with changes for the release. Tim Heuer has an excellent post explaining the details. If you’re developing for Silverlight 2 go read.

It’s exciting times in Silverlight Land!

Posted in  | Comments [0] 


Prism 2.0 – First Release Available on CodePlex

Saturday, September 20, 2008 7:19:52 AM (Eastern Daylight Time, UTC-04:00)

Earlier this spring the Microsoft Patterns & Practices group released the Composite Application Guidance for WPF, or Prism. Initially released for WPF, the team has been continuing their work, expanding the scope to include WPF and Silverlight.

The direction they are taking includes the ability to build applications that can provide both both Silverlight and WPF experiences through sharing and re-using code and components between the two environments. I’ve honestly learned a lot digging into Prism 1, and look forward into digging deeper into the new bits in the week ahead.

David Hill has a great post that includes more details here.

Congrats to the Prism 2.0 team on getting this turned around so quickly!

Technorati Tags: , ,

Posted in  |   | Comments [0] 


New "I'm a PC" Ads Released

Friday, September 19, 2008 6:27:25 PM (Eastern Daylight Time, UTC-04:00)

After doing that "Seinfeld thing" Microsoft has released a series of ads standing up for PC. I wonder if I should send in an "I own a Mac, but it runs Vista" clip?

 

The full set is available here

 

Technorati tags: , ,

Posted in  | Comments [0]