Matt Casto's .NET Journal RSS 2.0
 Monday, March 23, 2009

This is part 1 of my Silverlight 3 Feature By Feature series of blog posts.

No More Blank Slate

The first thing you may try after installing the Silverlight 3 Beta 1 Tools is creating a new Silverlight application. There is a new project template available called Silverlight Navigation Application. Using this project template creates a Silverlight project with a few things already set up for you. This is a departure from what we've had so far - a blank slate that is intimidating and doesn't really help new developers.

The new project contains the typical App.xaml but now with a bunch styles used in the main page. The MainPage.xaml is a generic, but nice looking, layout for an example Silverlight application. There are links to the Home and About views, which are both located in the Views folder of the project along with a view reserved for errors.

SilverlightNavApp_SlnExpl

Running the application without any changes shows the full page Silverlight application. Click on the links will change the URL in your browser and update the browsing history. You can use these URLs to go to a specific view. For example, from the About view copy the URL, then open an alternative browser and paste in the URL. Viola! Deep linking!

SilverlightNavApp_FirstRun

How It Works

The trick to the navigation, as implemented in the project template, is the Frame control in MainPage.xaml.

   1: <UserControl x:Class="SilverlightNavigation.MainPage"
   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:     xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation">
   5: ...
   6:     <navigation:Frame x:Name="Frame" Source="/Views/HomePage.xaml"
   7:                   HorizontalContentAlignment="Stretch"
   8:                   VerticalContentAlignment="Stretch"
   9:                   Padding="15,10,15,10"
  10:                   Background="White"/>
  11: ...
  12: </UserControl>

In particular, notice the navigation namespace. The project has a reference to the System.Windows.Controls.Navigation assembly which contains new controls and other things used for navigation.

The Frame is instructed to navigate in the Click event handler of the buttons.

   1: private void NavButton_Click(object sender, RoutedEventArgs e)
   2: {
   3:     Button navigationButton = sender as Button;
   4:     String goToPage = navigationButton.Tag.ToString();
   5:     this.Frame.Navigate(new Uri(goToPage, UriKind.Relative));
   6: }

I don’t exactly like the method of storing the destination page in the buttons’ Tag property, but that could easily be encapsulated by a custom NavigationButton control. Perhaps we’ll get one before RTW? I’ll definitely have to expand on this in a separate blog post.

HomePage.xaml and AboutPage.xaml are both Page objects instead of UserControl, which is typically the base control of new XAML files in a Silverlight 2 project. Its easy enough to add new navigable content to your application. Just add a new item to your project, and choose the Silverlight Page template in the Add New Item dialog.

Custom Navigation

What I wanted to do with my Silverlight Overview application was have a tree view control listing all of the examples, and each of these example pages showing up as a unique URL so I could link to a specific example. My original Silverlight Demo application had examples split into tab controls. Each tab was a separate XAML file. I could have modified these to be a Page instead of UserControl, but I wanted to break them down further and didn’t relish the thought of having 30+ Page files.

Using Reflector, I found that the Frame control’s Navigate method is using the NavigationService. Looking into this code wasn’t leading me anywhere so I decided to look at the Silverlight 3 documentation on MSDN. Interestingly, the only page that I found related to navigation, Navigation Overview, hasn’t been updated for Silverlight 3 and contains incorrect information. Finally I found Tim Heuer’s Navigation Framework screencast and blog post which shows how to use the UriMapper to accomplish what I’m looking for.

<nav:UriMapper x:Key="uriMapper">
    <nav:UriMapping Uri="Examples/{example}" MappedUri="/ExamplePage.xaml?example={example}" />
</nav:UriMapper>

Currently the UriMapper can only be defined in the App.xaml. Hopefully we’ll be able to move this to resource dictionary or even the same file as the Frame control.

Along with my changes to the App.xaml I added one Page to my project, ExamplePage.xaml.

<navigation:Page x:Class="SilverlightOverview.ExamplePage" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           Title="Example Page"
           xmlns:slo="clr-namespace:SilverlightOverview"
           Loaded="Page_Loaded">
    <Grid x:Name="LayoutRoot" Background="White">
        <slo:XamlViewer x:Name="viewer" />
    </Grid>
</navigation:Page>
   1: public partial class ExamplePage
   2: {
   3:     public ExamplePage()
   4:     {
   5:         InitializeComponent();
   6:     }
   7:  
   8:     private void Page_Loaded(object sender, RoutedEventArgs e)
   9:     {
  10:         if (this.NavigationContext.QueryString["example"] != null)
  11:         {
  12:             viewer.XamlFilename = string.Format("SilverlightOverview.Xaml.{0}.xaml",
  13:                                                 this.NavigationContext.QueryString["example"]);
  14:         }
  15:     }
  16: }

Running the project shows that my URLs to look like this.

SilverlightNavApp_URL

You can even try it for yourself if you have the Silverlight 3 Beta 1 runtime installed.

I really wanted to avoid the “Examples/” part of the URL since I only have one view, but there is a limitation built in which throws exceptions if I don’t have at least a something in there.

At this point all I had to do was add a TreeView and Frame to a Grid in my MainPage.xaml, bind the tree to a static list of example data, and my application is running. I’d like to figure out a way to dynamically change the page’s title, but I ran out of time. At first glace it appears that the only place to do this is from within the Page control, but I bet there’s way to get the currently displayed page from the Frame.

You can view the Silverlight Overview application here. At the time of writing this blog post, the deep linking is the only Silverlight 3 feature that’s been added.

Summary

The Good:  The Navigation Framework is a really great addition to Silverlight!

The Bad:  I’d rather be able to manually add items to the browser history and display pages based on the URL, but this solution will be fine for now. I think there might be a way to do that, but I could not find any other documentation and I ran out of time to look through everything with Reflector.

The Beautiful:  I finally have something to point to when Flash developers ask what Silverlight has to offer that Flash/Flex does’t.

(note – I wanted to summarize with the good, the bad and the ugly, but there’s nothing truly ugly about Silverlight 3 so I went with the opposite)

Monday, March 23, 2009 12:11:13 AM (Eastern Standard Time, UTC-05:00)  #    Comments [4] -
silverlight

I’m starting a series of blog posts where I’d go through each of Silverlight 3’s new features. To do this, I’m taking my Silverlight Demo application and updating it to include these new features.

Silverlight Overview

To start this off, I’ve converted my demo application to work with Silverlight 3 Beta 1 and posted it on CodePlex as Silverlight Overview. This application is a great interactive introduction and overview of XAML, controls and data binding in Silverlight. Currently the project only covers features through Silverlight 2, but I will be updating it as I cover each feature of Silverlight 3.

Feature By Feature

I’ll update this post with links as I add posts for each feature of Silverlight 3 to my series.

  • Deep Linking
  • Out of Browser (coming soon)
  • Data Binding (coming soon)
  • Perspective 3D (coming soon)
  • Easing Animations (coming soon)
  • Pixel Shader (coming soon)
  • Resource Dictionaries (coming soon)
  • Bitmap Enhancements (coming soon)
  • more when I get there ;-)
Monday, March 23, 2009 12:06:23 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight
 Friday, March 13, 2009
I'll be speaking at the Cincinnati Silverlight Firestarter event at the Microsoft office in Mason, OH on March 28th.  Following in the Cleveland event's footsteps, this is going to have local speakers and is a great full day introduction to Silverlight.  I'll be giving the Controls and Databinding post-lunch talk again. (Hopefully this time my laptop will work with the projector.)

 

Agenda:

 8:30 AM: Registration

 9:00 AM: An Introduction to Silverlight (Jeff Blankenburg)

 10:30 AM: An Introduction to XAML (Joe Wirtley)

 11:45 AM: Lunch break

 12:30 PM: An Introduction to the Tools (Josh Holmes)

 2:00 PM: An Introduction to Controls & Data Binding (Matt Casto)

 3:30 PM: Server Communication (Sam Nasr)

 4:45 PM: Giveaways and closing


To register for this event, please go to https://www.clicktoattend.com/invitation.aspx?code=136101


Hope to see you there!

Friday, March 13, 2009 9:17:55 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight
I was reading Shawn Wildermuth and John Papa's blog posts about all of the tools that they use for Silverlight development, and it finally pushed me to put a thought that's been rattling around in my brain into words.

Last weekend I was at the Art & Code conference at CMU in Pittsburg presenting, along with Tim Hibner, an introduction to Silverlight. Being in that environment reminded me of what it was like when I was a student and was looking at various programming languages. One of the things I was interested in doing back then was developing video games. I remember looking into Flash programming and was turned off by the cost of the development environment. To be honest, that was a while ago and I don't remember what the costs were, but I do remember the feeling that I couldn't bother with the hassle of learning the platform.

Developing video games like today's casual Flash games is a huge opportunity for an entry point to learning Silverlight. Just look at all of the Flash game sites out there. There are actually some Silverlight specific game sites getting started now like Silver Arcade and Silverlight Club. In fact, there is currently a Silverlight game development contest with a grand prize of $5000, which should definitely get people interested.

The first place people interested to start with Silverlight are pointed to is the Get Started page on the official Silverlight web site. This page starts out by linking to the Silverlight Tools for Visual Studio 2008 SP1, which in turn requires you to already have Visual Studio 2008 or Visual Web Developer Express installed with Service Pack 1. Assuming the user downloads the Visual Web Developer Express, they have a joy filled hour+ of baby sitting installs. Then, the second step is to download and install the Expression Blend 2 trial, and download and install the Expression Blend 2 Service Pack 1 on top of that. Gah! It goes on from there.

I'm seriously wondering how many people make it that far, or have given up at this point. I think the final straw for me would have been the fact that Blend is only a 30 day trial. What do I do after that? Pay $499 for Expression Blend or $999 for Expression Studio? No way! Even as a professional developer today I wouldn't pay that. And, sure, there's DreamSpark, but that's an extra hassle, and the get started page doesn't even mention it.

I love Silverlight, but its been easy for me since I've been developing on the Microsoft platform for over 10 years and I have access to MSDN downloads. Thank goodness for the fact that Blend is available through that, or else no one would bother with it.

Microsoft has done a great job with making free versions of its tools available lately, but for all the weight they're putting behind Silverlight I don't understand why they don't, at the very least, have an Express version of Blend. I would even suggest that there should be a free version of the entire Expression Suite, although a name like Expression Suite Express is kinda silly. :-)

Friday, March 13, 2009 7:09:13 AM (Eastern Standard Time, UTC-05:00)  #    Comments [10] -
silverlight | tools
 Monday, November 03, 2008
Last Saturday's Silverlight Firestarter event in Cleveland was a blast.  Being able to express my excitement for Silverlight to so many people (around 70 people showed) that had little to no experience with it was unbelievable.

I had problems connecting my Dell Inspiron 1720 laptop to the external display so the projector wouldn't work.  I had the same problem last Tuesday night at the CINNUG presentation, but this time John Stockton was there to save the day.  I was able to present all of my material on his machine without much of a hitch.

Jeff Blankenburg did a top notch job presenting the keynote and improvising in his Tools talk when his Blend install wouldn't work with Silverlight 2 projects.  Sarah Dutkiewicz was inspirational in her XAML basics session - she gave a clear introduction to XAML while being sick and barely able to talk!  Finally, John Stockton's presentation on Server Communicatiion in Silverlight showed why he's the man.  :-D

The project and slide files that I used for the presentations are available from my Sky Drive:

Monday, November 03, 2008 10:10:04 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight
 Tuesday, October 21, 2008
I'll be speaking at the Cleveland Silverlight Firestarter event on November 1st.  This event is going to have mostly the same structure as the NYC Silverlight Firestarter, but with (mostly) local speakers.  For instance, I'll be filling Shawn Wildermuth's shoes by giving the Controls and Databinding afternoon talk.

 

Agenda:

 8:00 AM: Registration

 9:00 AM: Keynote/Intro to Silverlight 2 (Jeff Blankenburg)

 10:30 AM: XAML Basics (Sarah Dutkiewicz)

 Noon: Lunch break

 1:00 PM: The Tools (Jeff Blankenburg)

 2:30 PM: Controls & Data Binding (Matt Casto)

 4:00 PM: Server Communication (John Stockton)


To register for this event, please go to http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032392883&Culture=en-US


Hope to see you there!

Tuesday, October 21, 2008 1:09:19 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight
 Tuesday, October 07, 2008
My submission to the Create a Sports Game in Silverlight Contest hosted by Team Zone Sports ended up in second place!

The game is called Ball Blocks because I couldn't come up with a better name at the time.  You play by drawing a square over the balls where the four corners of the square are on top of the same type of ball.  The bigger the square (more balls inside of it) the more points you get and the more time gets added back to the timer.

The game currently has a bug in it where it can freeze the browser during the game over animation when time expires.  This seems to happen more often on slower machines.  It may be because of the spinning textblock ... I'm just not sure.

Because of time spent trying to fix this bug, I didn't get sounds fully implemented and didn't get a far into the game development as I'd hoped.  I'm hoping to spend some more time on it some time soon and get some of the features I'd originally envisioned implemented.

I've created a Ball Blocks project on CodePlex and uploaded the code.  The project has been updated to work in Silverlight 2.0 RC0 so it should be ready once Silverlight 2 is released.

Tuesday, October 07, 2008 10:35:12 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight
 Monday, April 21, 2008

This is a very simple animation that can be used just about anywhere.

[[ If you're viewing this post through an RSS reader, you won't be able to see the Silverlight example ]]

Following is my Page.xaml for this example.  There was no code needed.

<UserControl x:Class="AnimationSample.Page"
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="300" Height="150">
  <Grid x:Name="LayoutRoot" Background="White">
    <Grid.Triggers>
      <EventTrigger RoutedEvent="Grid.Loaded">
        <EventTrigger.Actions>
          <BeginStoryboard>
            <Storyboard x:Name="CrawlingBorder" RepeatBehavior="Forever">
              <DoubleAnimationUsingKeyFrames Storyboard.TargetName="rectangle" 
                Storyboard.TargetProperty="(Shape.StrokeDashOffset)" BeginTime="00:00:00">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0" />
                <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="5" />
              </DoubleAnimationUsingKeyFrames>
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger.Actions>
      </EventTrigger>
    </Grid.Triggers>
    <Rectangle Stroke="Green" StrokeThickness="6" StrokeDashArray="3,2" StrokeDashCap="Round" 
               Margin="20" StrokeDashOffset="0" StrokeLineJoin="Round" x:Name="rectangle">
    </Rectangle>
    <TextBlock FontFamily="Lucida Sans Unicode" FontSize="24" 
               Text="Crawling Border" FontWeight="Bold" 
               HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#FFDE680A"/>
  </Grid>
</UserControl>
Monday, April 21, 2008 9:55:36 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight

I gave a talk at the Central Ohio Day of .NET last Saturday about Silverlight 2.  The presentation was written in Silverlight 2 Beta 1 and included examples of functionality built into Silverlight versions 1 and 2, and the beginning steps in creating the presentation itself.

I have much more planned to be added to the presentation, so I created a CodePlex project called PresentLight.  I'm hoping that other people will like the idea of giving a presentation in the technology that they're speaking about, and maybe they'll use the framework or even add their own content!

I uploaded a slightly older version than the one I gave at CODoDN to silverlight.live.com, check it out by clicking on the following preview image.  The XAP is 14 MB so expect a decent wait for everything to load ... I need to reduce the size.  I'll update this post with a better example as soon as I have it available.

Much thanks goes out to Jeff Blankenburg for building the original slide deck that I based this presentation on.  Also, I got the idea from David Sleeckx's WPF presentation, which is an excellent way to get an overview of WPF.

Using the Presentation

You can navigate the slides through the menu on the left, or move forward one slide by clicking on the header area.  A few of the slides don't have much at first, but clicking in the slide area will show text which was talking points for that part of the presentation.  The interactive slides in the middle should be pretty self explanatory - you can modify the XAML in most of the examples to see changes in real time.

The screen shots at the end can be clicked on to view the full size.  I wanted to keep the entire presentation in Silverlight, so I was trying to use screen shots instead of jumping into Visual Studio.  These slides were taking over an hour each to prepare, because I was trying to give each one a different type of animation.  I think they ended up being a little disjointed though - its much more natural to see someone working with the environment than seeing screen shots of some code, then the solution explorer, then XAML.  I'm definitely going to have to give more thought to that area.

Plans for the Future

I plan to have the slides stored in data rather than hard coded in the page code behind.  I'm going to integrate more examples, such as Isolated Storage, Communications with web services and through sockets, and dynamic languages integrated directly into the slides, like I did with the XAML examples.

Also, I'm going to expand more on some of the user controls that I created as part of the application.  I already went into the scrolling textbox control in my last post, so there will be more of that on the way.

Monday, April 21, 2008 9:15:26 PM (Eastern Standard Time, UTC-05:00)  #    Comments [2] -
silverlight
 Sunday, April 13, 2008

The TextBox control included with Silverlight 2 Beta 1 is a welcome addition.  There was no such control in previous versions of Silverlight, including the alpha.

Unfortunately, the TextBox control is very limited at this point.  It does not support scrollbars when it's content is larger than it's size.  You can "scroll" the next by moving the cursor, but that's just enough to make it functional.  Selecting text past what's visible doesn't automatically scroll to the cursor.  Also, there's no text wrapping, although setting the AcceptsReturn property to True will allow line breaks in the text.

I wanted to have a text box with a little more functionality for my projects, so I decided to see what I could do.  What follows is the simple ScrollingTextBox control that I created.  I didn't spend a ton of time on this because I fully expect this "missing" functionality to be included by Beta 2, or at least by the time Silverlight 2 is released.

 

To build this, I first created a Silverlight application project and added a Silverlight control called ScrollingTextBox.

<UserControl x:Class="PresentLight.ScrollingTextBox"
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid x:Name="LayoutRoot">
    <ScrollViewer x:Name="sv" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
      <TextBlock x:Name="hiddenTextBlock" Opacity="0" />
      <TextBox x:Name="tb" AcceptsReturn="True" TextChanged="tb_TextChanged" />
    </ScrollViewer>
  </Grid>
</UserControl>

The internal TextBlock control is only there to serve as a way to get the actual size of the text.  TextBlock controls will automatically resize to fit their contents, so if I keep it's text the same as the internal textbox control, it will resize accordingly.  The default value for Width and Height dependency properties in Silverlight is Auto, which causes this resize behavior.

Since the ScrollViewer control automatically set's it's scrollable region to fit it's contents, it will be resized to fit the internal textblock.  The internal textbox control will automatically resize to fit it's container, since I haven't set any width or height on it.

Then I added a dependency property for setting the control's Text, which takes care of setting the textbox's text value.  Finally, I handled the TextChanged event on the internal TextBox control to resize based on my internal TextBlock's size.

using System.Windows;
using System.Windows.Controls;

namespace PresentLight
{
    public partial class ScrollingTextBox : UserControl
    {
        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set
            {
                SetValue(TextProperty, value);
                tb.Text = value;
            }
        }

        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(string), 
                               typeof(ScrollingTextBox), null);


        public ScrollingTextBox()
        {
            InitializeComponent();
        }

        private void tb_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (hiddenTextBlock != null)
            {
                hiddenTextBlock.Text = tb.Text;
                tb.Width = hiddenTextBlock.ActualWidth;
                tb.Height = hiddenTextBlock.ActualHeight;
            }
        }
    }
}

The result is a marginally better control.  There are a lot of possible improvements for me to make, such as possibly handing the selection changed event on the textbox to scroll the ScrollViewer to the cursor's position.  That will have to wait for a future post.

Sunday, April 13, 2008 9:41:18 AM (Eastern Standard Time, UTC-05:00)  #    Comments [2] -
silverlight
 Saturday, April 12, 2008

I haven't been posting much lately because I've been very busy preparing for my session at the Central Ohio Day of .NET.  I'm creating a presentation about Silverlight 2.0 Beta 1, but with a twist - the presentation is actually a Silverlight application!

Templates

For the last day or so I've been working on getting my application's main control to use templates to define the interface.  This gives me the option to create multiple "skins" for the application.

To accomplish this, I've been referencing two very excellent tutorials by Jesse Liberty and Shawn Burke.  But, as usual for me, I ran into a problem that sucked up a ton of time.

The Problem

I was trying to set up my template to include buttons for navigation between slides.  I started by building a simple XAML interface for the buttons, like so.

<StackPanel Orientation="Horizontal">
    <Button Height="75" Width="75" Margin="0,0,8,0">
        <TextBlock Text="First" HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Button>
    <Button Height="75" Width="75" Margin="0,0,8,0">
        <TextBlock Text="Prev" HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Button>
    <Button Height="75" Width="75" Margin="0,0,8,0">
        <TextBlock Text="Next" HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Button>
    <Button Height="75" Width="75">
        <TextBlock Text="Last" HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Button>
</StackPanel>

 

And that looks good enough for this example.

 

Then I took that same XAML and put it into a template stored in the application resources (in App.xaml).

<Application.Resources>
  <Style x:Key="TestTemplate" TargetType="pl:Presentation">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="pl:Presentation">
          <StackPanel Orientation="Horizontal">
            <Button Height="75" Width="75" Margin="0,0,8,0">
              <TextBlock Text="First" HorizontalAlignment="Center" VerticalAlignment="Center" />
            </Button>
            <Button Height="75" Width="75" Margin="0,0,8,0">
              <TextBlock Text="Prev" HorizontalAlignment="Center" VerticalAlignment="Center" />
            </Button>
            <Button Height="75" Width="75" Margin="0,0,8,0">
              <TextBlock Text="Next" HorizontalAlignment="Center" VerticalAlignment="Center" />
            </Button>
            <Button Height="75" Width="75">
              <TextBlock Text="Last" HorizontalAlignment="Center" VerticalAlignment="Center" />
            </Button>
          </StackPanel>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</Application.Resources>

And modified my Page.xaml to have my Presentation UserControl class (modeled after Shawn Burke's tutorial) with the template applied as a style.

<local:Presentation x:Name="PresentationControl" Style="{StaticResource TestTemplate}" />

But running this treated me to a browser window that's stuck loading.  My break point in OnApplyTemplate in my Presentation class never got hit.  Pausing Visual Studio didn't tell me anything, so I knew it wasn't stuck in a loop.  This had me stuck for several hours.

The Solution

What I eventually found was that certain things that are perfectly acceptable XAML in a user control won't work in a template.  Furthermore, if Silverlight encounters these elements in the template it just hangs.

The problem XAML was the buttons.  Instead of including your actual buttons in your template, you should instead create a separate template for the buttons, and reference that as your button style.

<Style x:Key="TestButton" TargetType="Button">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="Button">
        <Button Width="75" Height="75">
          <Button.Content>
            <ContentPresenter Content="{TemplateBinding Content}" 
                              HorizontalAlignment="Center" 
                              VerticalAlignment="Center" />
          </Button.Content>
        </Button>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

Then modify the previous template to use the new button template.

<Application.Resources>
  <Style x:Key="TestTemplate" TargetType="pl:Presentation">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="pl:Presentation">
          <StackPanel Orientation="Horizontal">
            <Button x:Name="FirstButtonElement" Content="First" 
                    Style="{StaticResource TestButton}" Margin="0,0,8,0" />
            <Button x:Name="PreviousButtonElement" Content="Prev" 
                    Style="{StaticResource TestButton}" Margin="0,0,8,0" />
            <Button x:Name="NextButtonElement" Content="Next" 
                    Style="{StaticResource TestButton}" Margin="0,0,8,0" />
            <Button x:Name="LastButtonElement" Content="Last" 
                    Style="{StaticResource TestButton}" />
          </StackPanel>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</Application.Resources>

Finally, this works.  It looks the same, but now I can take the template and make it look much nicer if I want.

Hopefully this tip will help others working on templating in Silverlight avoid the pitfalls I ran into.

Saturday, April 12, 2008 5:45:08 PM (Eastern Standard Time, UTC-05:00)  #    Comments [1] -
silverlight
 Wednesday, March 05, 2008

I arrived at work this morning only to find that the Silverlight 2.0 Beta 1 plugin and some documentation was discovered and available for download.  A few hours later the SDK and documentation was available, then after the keynote at Mix that whole lot was officially released.  I couldn't wait to try it out when I got home.

Unfortunately, the install experience hasn't been good.  I've got the Silverlight 2.0 plugin and SDK installed, but I can't get the tools for Visual Studio 2008 installed.  Here's step by step what I've done so far.

  1. Downloaded and installed the Silverlight 2 Beta 1 plugin (runtime) without a hitch.
  2. Downloaded Silverlight 2 Beta 1 SDK, Silverlight 2 Beta 1 Tools for Visual Studio 2008, and Expression Blend 2.5 March Preview.
  3. Uninstalled Silverlight 1.1 Alpha Tools for Visual Studio 2008 and Expression Blend 2 December Preview.
  4. Installed Silverlight 2 Beta 1 SDK.
  5. Tried to install Silverlight 2 Beta 1 Tools for Visual Studio but got the following error message:
    1. An Error Has Occurred:
      Silverlight Tools cannot be installed because one or more of the following conditions is true:

      1. Visual Studio 2008 RTM is not installed.
      2. The Web Authoring feature of Visual Studio is not installed.
      3. A previous version of the Silverlight Runtime is installed.
      4. A previous version of the Silverlight SDK is installed.
      5. The Visual Studio Update KB949325 is installed.
      6. A previous version of Silverlight Tools is installed.

      To continue, please install or uninstall the appropriate products and run this installer again.

  6. Verified what I had installed.  I've got Visual Studio Team System 2008 RTM, Microsoft Visual Studio Web Authoring Component, Silverlight runtime, Silverlight 2 SDK, Silverlight 1.0 SDK.  Oops, maybe that's the problem?  Also, I didn't uninstall Silverlight 1.1 Alpha runtime before installing Silverlight 2.0 runtime, but that shouldn't be a problem.
  7. Uninstalled Silverlight runtime and both SDKs, then rebooted for good measure.
  8. Installed Silverlight runtime, 2.0 SDK, ran silverlight_chainer.exe again and got the same error.
  9. Did a web search and found http://blog.steeleprice.net/archive/2008/03/05/1362.aspx which mentions a registry key that needs to be removed, but I don't have that registry key on my system.

At this point I can't find any more information through web searches or in the Silverlight.Net forums.  I'm posting this problem in the forums with a link here for a complete description of the problem.

I was really hoping to get few things done in Silverlight 2.0 and posted online tonight, but I'm kind of stuck and frustrated at this point.

UPDATE

Chad Campbell responded to my Silverlight.net forum post with a solution.  The solution definitely isn't something that I'd say is obvious, but hey, do whatever works.  I'm just a little surprised that I'd have more trouble with the beta than the alpha.

A big thanks goes out to Chad for his quick reply.  I'm definitely going to have to buy his book now!

Oops!

Even though the tools are now installed, something is still wrong.  Here's what I get when I try to create a Silverlight project in Visual Studio 2008.


Resolution

It turns out that the Silverlight 2 Tools Beta 1 for Visual Studio 2008 installs the Silverlight 2 Beta 1 runtime and SDK as part of the package.  This causes a problem if you already installed the plugin or the SDK.  I uninstalled everything Silverlight related, then installed silverlight_chainer.exe, this time successfully.  I'm now ready to go.

Wednesday, March 05, 2008 9:56:34 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
betas | silverlight
 Thursday, February 21, 2008
I had to response to my soon-to-be-former boss' post about how an architect packs when moving offices.

A Silverlight guy could pack today with some great looking boxes that work with all major moving trucks, but they won't really hold all of his stuff.  They're kind of like those XAML boxes, but with huge gaps.  He feels the need to defend his box choice when compared with the competitor's boxes, which have been in production for years and total market penetration.

The Silverlight guy would rather wait another month or so, for the 2.0 beta of the box.  This version will solve all of his packing needs, can be loaded 1000 times faster than other common boxes and comes with a license allowing it to be used immediately.  The 2.0 boxes will also feature data cateloguing, content memory, multiple languages and can be used to build even better composite boxes.  So the Silverlight guy will probably wait until after the big conference when the new box is supposed to be announced.

Thursday, February 21, 2008 9:12:15 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight
 Friday, December 21, 2007
I haven't posted in a long time, not because I haven't wanted to, but because I've been spending every minute of my free time working on a Session Scheduler application for CodeMash.

I can now talk about it because it's gone live!

The session scheduler was written in Silverlight 1.1 Alpha.  I would have written it in Silverlight 1.0 but I really wanted to be able to use Isolated Storage.  With Isolated Storage I was able to make the application store any changes the user makes locally, so the next time you go to the site it will be exactly where you left it and retain any of the sessions you've scheduled.

Using the Session Scheduler

The default view of the scheduler shows all sessions and Wednesday.  Unfortunately I didn't get around to implementing some sort of scrolling for the session list, but it was low on the list of features since the typical view of the application only has 6-8 sessions being shown at once.

You can click on the track buttons in the upper left to filter the session list by that track, or you can click on a session slot on the right (the agenda) and the session list will filter based on which sessions are available for that time of the day.

If you hover over a session menu item the session's details will drop down.  From that view, the green button can be used to schedule that session in your agenda.  Just hovering over the button will automatically show the time slot in the agenda where that session will occur.  Also, clicking on the speaker's name will show the speaker's bio.  This will show a picture of the speaker soon, but I'm having an issue displaying images in there at the moment.

You can click on the link image in the upper right to get a URL that can be used to send your custom agenda to someone else.  Currently, if you view another person's custom agenda it will overwrite any changes you've made yourself.  A workaround for this would be to copy a link to your agenda first, then use it once you're done looking at the other user's agenda.  I'm currently working on modifying this to save a history of agendas that you've looked at.

You can view my schedule here. ;-)

You can also click on the email image to view a simple HTML page with your custom agenda allowing you to print or email it from there.

I will be following up this post with several more describing the roadblocks I hit, and how I resolved, or worked around, them.

Friday, December 21, 2007 8:42:59 AM (Eastern Standard Time, UTC-05:00)  #    Comments [2] -
codemash | silverlight
 Friday, September 28, 2007
So I'm here at the Silverlight DevCamp in Chicago with my colleague at Quick Solutions, Steve. We're just about to get started. It looks like the schedule for tomorrow is pretty full and will be going more in depth than the high level, overview types of presentations. I'm excited!

Labels: ,

Friday, September 28, 2007 7:05:00 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight | SilverlightDevCamp
 Tuesday, September 25, 2007
I haven't posted in over a week about my progress with my 30 day sprint to learn Silveright because it died. Right after the last post I ran into several roadblocks, the largest of which was the loss of enough free time to regularly spend the time needed. Also, after a couple of days of inactivity I lost my motivation.

This morning I realized that today is the 30 day mark. So did my expirement fail? In the sense that I didn't spend the hour per day that I pledge to myself, yes it did. But, in the sense that I learned a lot about Silverlight and got myself into more of a habit of setting aside time to learn, it was a success.

The next time I decide to do a sprint of this kind, I will check with my event planner (my wife) and make sure that the schedule will allow for the time I want to spend. Also, I think I'll go for a shorter time span. I think my next sprint will probably be either 2 weeks or 15 days, and I might try to lay out a goal for each day ahead of time.

Right now I'm involved in a project in my free time to build a Silverlight application that has a pretty aggressive timeline, but I'll try to post examples of things I've figured out or problems I ran into along the way. I also have several ideas of some fun apps to write that I'll blog about as well.

Labels: ,

Tuesday, September 25, 2007 7:40:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight | sprint
 Thursday, September 13, 2007
Tonight was the first chance I've had to spend any time with Silverlight since the weekend. When it rains, it pours. When septic tanks back up, you have to rearrange your priorities a bit. :-)

Tonight I started a new Silverlight 1.1 project in which I created a few textareas that I'm planning on reading and modifying through my Silverlight application. I was going through the Dom Access Quickstart and only made it to the third step in the first section before hitting a roadblock.

The quickstart says to create a variable of type HtmlDocument, but Visual Studio doesn't list it in Intellisense! My first thought was maybe that the System.Web name space needed to be referenced, but when I tried to add a reference to the project I didn't see it as an option. In fact, there are only a handful of assemblies available to reference by default.


My next thought was to hit the Silverlight.net Forums and look for a post where someone else had the same problem. Guess what? The forums don't have a search function. After reading through 3 pages I gave up and tried Google.

My search for 'silverlight htmldocument' led me to "Silverlight how-to: let the DOM interact with Silverlight". While the demo is very basic and regurgitates what's already available in the Quickstarts, it had one piece of information that made all the difference: it mentions that I need to add a reference to System.Windows.Browser in order to get to the HtmlDocument.

In retrospect, I could have probably found this a lot quicker if I'd just searched for HtmlDocument on MSDN. However, when I tried this, all I found was links to HtmlDocument in System.Windows.Forms. Buried in the search results I did find a link to Dave Relyea's post "Calling Javascript from C#" which is a much better resource.

This solved my problem and I'm ready to move on. Maybe tomorrow I'll be able to make some headway on some of the ideas I want to try.

Labels: ,

Thursday, September 13, 2007 8:46:00 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight | sprint
 Saturday, September 08, 2007
Component One has a controls suite called Sapphire for Silverlight 1.1 that has a lot more promise than the Telerik one.

And there's a textbox control! Too bad that hitting backspace in their textbox trigger's Firefox's back button. I found that bug in the first 10 seconds. Too bad.

Labels:

Saturday, September 08, 2007 1:56:00 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight
Telerik released it's RadControls for Microsoft Silverlight product on the same day Silverlight 1.0 was released. The cube control is cool, but the other ones don't really seem to be all that special. The button and layout controls in particular will probably be obsolete once Silverlight 1.1 is released. Still, it's nice to see what kinds of things will be available soon.

Labels:

Saturday, September 08, 2007 8:37:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight
 Friday, September 07, 2007
I found that there are some generic controls included with the Microsoft Silverlight 1.1 SDK Alpha September Refresh. (We need an abbreviation for that; it's too long. How about MS1.1SDKASR?)

From the Welcome page in the MS1.1SDKASR, click on the Sample UI Controls for the readme, which includes this:
This package contains sample source code for some common
UI controls for the Silverlight managed code framework.

You may customize these controls and use them in your
Silverlight applications.

In this package, you will find a functional solution
with C# code files representing control behavior and XAML
markup files representing the visual aspects of the control.
Also included in the solution is test code that demonstrates
usage of the controls, how events can be hooked up and
handled, etc.

The following sample controls are included:
* Button
* Slider
* ScrollBar
* ScrollViewer
* ListBox


Wha? No Textbox control? Let's hope that they're working hard on one and it makes it into the 1.1 release.

I spent the day pretty much going through the sample controls and seeing how they work. I don't think they're suitable to be used in a production application, but they're good for learning.

Labels: ,

Friday, September 07, 2007 8:21:00 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight | sprint
Day 12

On Day 11 I came to the realization that there wasn't any supported XAML in Silverlight that allowed text entry and that you had to tie your Silverlight app to an HTML textbox/textarea in order to do this.

I decided to try putting an HTML textarea over a Silverlight app and see how I could get them to work together. I wanted to have a javascript method called when the contents of the textarea changed, and have that javascript method call into the Silverlight app. After an hour or so of frustrating trial and error and reading through documentation online, I realized that you can't call Silverlight 1.0 from javascript.

Day 13

Up to now I've been working on a system with the Silverlight 1.0 SDK and Visual Studio 2008 March CTP. I have a very slow internet connection and my laptop leaves a lot to be desired, so this was holding me back from installing Visual Studio 2008 Beta 2. Last night I decided the time had come.

I had started the download of Visual Studio 2008 the night before, which took around 23 hours. At around 8pm I uninstalled the March CTP, then uninstalled all .NET 3.5 stuff hanging around. This all took almost an hour and a half. I then installed Beta 2, the Alpha Tools, and downloaded the Silverlight 1.1 Alpha SDK.

At this point it was almost 11pm and I was out of time to spend for the evening. So much for my Day 13 of the sprint. I realy hope to get further on the text entry experiments this weekend.

Labels: ,

Friday, September 07, 2007 6:49:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight | sprint
 Thursday, September 06, 2007
I noticed this morning that the Silverlight Get Started page states that there's a Silverlight 1.1 Alpha September Refresh. I don't remember seeing anything in Scott Guthrie's post about a September specific version of the 1.1 Alpha Refresh. I downloaded the file and it has the same size and version as the 1.1 Alpha Refresh that I downloaded last month. The Get Started page also has a link to the Silverlight SDK 1.1 Alpha September Refresh. What's going on here?

I found this comment from Scott Guthrie in his above mentioned blog post.
The 1.1 refreshes from MIX to now have mainly just been updates to keep in sync with the Silverlight 1.0 code-base. Now that Silverlight 1.0 has shipped, the upcoming refreshes of 1.1 will be feature updates with more functionality. So you'll start to see more functionality appear soon.

Labels:

Thursday, September 06, 2007 6:27:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight
 Wednesday, September 05, 2007
Silverlight 1.0 has been released! Also, it looks like Microsoft is partnering with Novell to make sure that Moonlight fully supports the Silverlight 1.0 and 1.1 programming models.

Source

Labels:

Wednesday, September 05, 2007 10:10:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight
Days 8-10

Days 8 through 10 were labor day weekend and I was out of town for most of that time. I did get a chance to play with Expression Blend more and read the SDK and Expression Blend documentation about various XAML keywords, polygon and polyline in particular.

I was trying to figure out how to create some basic shapes in XAML. My first attempts were by creating a polygon with the correct points, but I found myself getting massively sidetracking trying to remember basic geometry from my freshman year of high school. After reading more documentation I found that I could draw some different shapes in Blend, then combine them into a single path, which might be the best way to accomplish what I was going for.

Day 11

Last night, I was trying to create a basic form in Silverlight. I started by looking at the documentation for the textblock object, and found all kinds of interesting ways that text can be transformed and output, including the run and linebreak objects. Unfortunately, I didn't find any information about how to allow the user to enter text into a silverlight app.

Eventually I found the Using Input Method Editors for Text Entry in Silverlight screencast which covers what I was looking for, in addition to other interesting features.

I've got to say I'm pretty disappointed to learn that in order to do text entry in a Silverlight app, I've got to actually overlay an HTML textarea over the Silverlight control, and use javascript to read/write text from that textarea.

I have a lot of ideas to experiment with such as whether I can create a textarea with a transparent background and no border, which would allow me to do a better job integrating it with the Silverlight control. Or perhaps I could have a text area that allows entry, but what's entered is immediately hidden and reproduced in the a textblock in XAML, fooling the user into thinking that they're entering text directly into Silverlight.

Labels: ,

Wednesday, September 05, 2007 7:12:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight | sprint
 Thursday, August 30, 2007
Tonight I went through the Silverlight QuickStart Using Microsoft Expression Blend tutorial. I didn't do everything in the tutorial and tried some experimentation as well which was pretty fun. I'm really glad I did the quick start because just starting up Expression Blend and trying to figure things out wasn't working for me.

Note - if you're using Expression Blend 2 August Preview some things in the quick start tutorial have changed. In particular, creating my first timeline was frustrating because the button to add a new timeline moved between the May and August previews.

Also, I found designwithsilverlight.com which has some great looking tutorials that I'll go through once I'm done with the materials from silverlight.net.

Labels: ,

Thursday, August 30, 2007 9:04:00 PM (Eastern Standard Time, UTC-05:00)  #    Comments [1] -
silverlight | sprint
Real life has prevented me from spending at least an hour with Silverlight this week. Even when you make a commitment to yourself, there are some things that take a higher priority.

That said, I did find a cool blog that has posts related to making games for Silverlight - Silverlight Games 101

In fact, the silverlightrocks.com site could be a good source of information as it grows.

Since you can get through the learning materials online pretty quickly, spending 30 days focusing on Silverlight means that most of the time will be working with actual code. It helps to have a real project to work on, and I am lucky enough to be involved in one. It's not a commercial project, but more of a community project that I'm donating time to. More detailed information will be forthcoming.

Labels: ,

Thursday, August 30, 2007 10:52:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [2] -
silverlight | sprint
 Monday, August 27, 2007
I didn't have as much time to spend on day 2 as I did the first day, but I did get some things done. Mostly I read through some of the quickstarts and watched some of the videos at the Silverlight site.

JD suggested to me that I keep a list of resources to help manage my thoughts. I've been saving interesting pages to del.icio.us with a Silverlight tag for a while now, but I think I'll definitely be more cognisant to save everything I run into.

http://del.icio.us/mattcasto/silverlight

Probably the most interesting thing that I found was Silverlight Pad, an online equivalent to XAML Pad. Looking at what's available there and making changes to see what happens is a great way to get a feel for what's going on.

Labels: ,

Monday, August 27, 2007 6:37:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight | sprint
 Saturday, August 25, 2007
For my first day of my 30 day learning sprint focusing on Microsoft Silverlight, I'm going to go through the Quickstarts on the community Silverlight website.

Before starting with the Quickstarts, I had to set my machine up. Based on Scott Hanselman's post "VS 2008 and .NET 3.5 Beta 2 Releases Made Easy," I downloaded and installed the following:
Then I got confused. I wasn't sure whether to start with 1.0 or 1.1. Silverlight 1.0 is at the release candidate stage with a go live license, so it seems like a safe bet. But with 1.1 I can program with c# on the client. I'm 95% more proficient with c# than with javascript, so this is a tough one.

While digging around for more details, I found Jesse Liberty's blog posts about learning Silverlight from a .NET developer's perspective. Excellent! Not only is there are series with me as a target audience, but one that is a lot like my planned learning exercise, AND it's by the guy who wrote the book that I started my .NET learning with as well!

Jesse's post about the differences between 1.0 and 1.1 lead me to the Silverlight Runtimes Matrix which shed some more light.

I could deal with just using javascript for my initial learning, but when I saw that isolated storage wasn't supported in 1.0 that tipped the scale. I'm not sure exactly why ... it could be because one of the first cool demos I saw of Silverlight was how the isolated storage was shared between all browsers. I found the demo again on ExplosiveDog.com's "Silverlight Isolated Storage" post.

I switched targets and downloaded the Silverlight 1.1 Alpha Refresh and Silverlight 1.1 SDK. One thing I'm still confused about is whether the 1.1 SDK is up to date with the 1.1 alpha refresh. I kind of doubt it because the search results on Microsoft Download have it listed with a date of 5/17/2007, while the Silverlight 1.0 SDK RC has a date of 7/27/2007. I decided to hold off on installing the 1.1 SDK, but I'd already installed the 1.0 SDK RC so we'll see what happens.

At this point I've more than used up my first day's amount of time. Maybe later tonight I'll look at some of the samples in the quickstarts, but now my eyes are tired from staring at the monitor for too long. Too bad there aren't any books out yet, because I could really use some printed text at this point.

Labels: ,

Saturday, August 25, 2007 1:54:00 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
silverlight | sprint
Today I've decided to start the 30 day learning sprint that I've been putting off for a while now. The technology that I've decided to learn is Microsoft Silverlight. This was my plan from a few months ago but procrastination lead me to put it off until now.

For the next 30 days I am making a pledge to myself to spend at least an hour each day focusing solely on a task that will help me learn Silverlight. Whether that task is reading a tutorial or document, writing or debugging code, or anything else related, the point is that I commit to spending this amount of time each day on the goal.

I hope that the one hour requirement will allow this to fit into my family life and schedule without being disruptive. Also, by writing this blog post I'm not only committing this to myself, but hopefully the public announcement will help me stay on task. (Plus, I can always come back and delete this post).

I will also post one blog entry detailing what I planned on accomplishing for each day, how it went, and what the outcome was.

Labels: ,

Saturday, August 25, 2007 1:41:00 PM (Eastern Standard Time, UTC-05:00)  #    Comments [6] -
silverlight | sprint
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Matt Casto
Sign In
All Content © 2010, Matt Casto
Theme based on DasBlog theme 'Business' created by Christoph De Baene (delarou)