Archive

Archive for the ‘WPF’ Category

MultiBinding in WPF

January 21, 2009 3 comments

In my current application, I have a ListBox that displays images horizontally.  Basically it is a WPF FilmStrip (without the control) with some additional features.  One feature is a toolbar that includes navigation buttons.  First and Last buttons are easy: they are always available and always navigate to the first or last image in the list.  The Previous and Next buttons are also easy to navigate, by simply incrementing or decrementing the SelectedIndex value of the ListBox.

Simple IValueConverter

While WPF seems to automatically handle numbers less than 0 and greater than the Items.Count, I only want the Previous and Next buttons enabled based on the SelectedIndex.  If the index is 0, I do not want the Previous button enabled, and if the index is the last one, I do not want the Next button enabled.  To accomplish this, I need to convert the SelectedIndex to a Boolean, so I wired up an IValueConverter.  In the case of Previous, it is a simple task in the converter to just compare the SelectedIndex to 0:

    public class SelectedItemIndexIsNotFirstToBoolean : IValueConverter
    {
        #region IValueConverter Members
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is int)
            {
                int index = (int)value;
                return (index > 0);
            }

            return false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

Basically, the converter returns True if the value is > 0 so that IsEnabled will be True.  Now to wire this up, just add the Converter to the Binding:


The XAML above does several things: first, the Path is the Property name of the Element (specified by ElementName) we want to send to the Converter. The Converter is a reference to a Resource instance of the Converter, which means you’ll have to add a line for this in Window.Resources:


If you aren’t impressed yet, think about what just happened: I bound a boolean value of a control (it could be any of them, not just IsEnabled) to the SelectedIndex value of a ListBox with no code behind or events. I don’t include the Converter classes as code behind, because I can easily see working up a DLL full of these and using them in many applications.

MultiBinding using IMultiValueConverter

The Next button, however, was not as straight forward as the Previous button.  In this case, I needed to check the SelectedIndex against the Items.Count property to see if this is the last Image in the list.  At first, I tried to use RelativeSource binding to navigate the tree and send the ListBox itself, but I quit for two reasons.  The first reason is it got hairy in a hurry I couldn’t get it to work.  The second reason is that I could see using the resulting IValueConverter for other applications and Control types, so I didn’t want to limit it.  The answer therefore became finding a way to send both the SelectedIndex and the Items.Count to a IMultiValueConverter.

A IMultiValueConverter functions much like an IValueConverter, receives an object[] as the first parameter.  Then, like the IValueConverter, we can simply process the array values and use them to determine the return value:

public class SelectedItemIndexIsNotLastToBoolean : IMultiValueConverter
{
    #region IMultiValueConverter Members

    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (values[0] is int && values[1] is int)
        {
            int index = (int)values[0];
            int count = (int)values[1];
            return (++index != count);
        }

        return false;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    #endregion
}

As you can see, other than processing multiple values, there is very little difference between the two.  The question then becomes “how the heck do I wire this thing up?”  If you are using Blend, I have bad news: as far as I can tell there is no way to wire up MultiBinding in Blend.  The good news is that it was really easy to do in XAML and required no RelativeSource or anything funky like that:


    
        
            
            
        
    
    

I broke the IsEnabled property out of the button and added a MultiBinding tag to it that contains all the magic.  You have to specify the Binding tags in the order the IMultiValueConverter is expecting them.  The statement is very simple, referencing the ElementName and Path as above for each value to be passed to the Converter.  I did discover something interesting: look at the second one and you’ll see I indicated “Items.Count”.  I didn’t actually think this would work since I am referencing a subproperty, but the Count came through just fine. And of course, don’t forget to add a reference to the Converter to Window.Resources.

Conclusions

There is some concern out there that too much stuff will get shoved into XAML just because we can.  The question you have to ask yourself is whether or not the time invested and the result are worth it.  In this case, I think it is justified.  Most of the time I invested here was learning the technique, which is a cost I won’t have to pay again.  It also ended in much less coding in my button Click events, and is completely reusable for different scenarios and future projects.

Categories: WPF

Accessing Command Line Arguments in WPF

January 12, 2009 4 comments

The software I’ve been developing needs to be accessible from the command line, and in those cases it needs to be able to receive parameters in order to properly initialize the application instance.  I’d done this plenty of times in Windows Forms, but when I started looking for the public static void main entry method, I couldn’t find it.  It didn’t take long to find the answer, but I thought it was worth sharing.

Windows Forms

In Windows Forms, the way I’ve always done this is to add a string[] args parameter to Main(), which is found in “Program.cs”.  Then I override the Form constructor and pass the array to the Form.  You can also use Envorinment.GetCommandLineArgs().  That post had a couple of comments where the users seemed concerned because the first element of the array contains the full path to the executable.  If you choose this method, simply ignore index 0 and you can access the parms in exactly the same way.

WPF

The method in WPF is the same basic concept, but it occurs in a slightly different way.  Right off the bat, you’ll notice there is no “Program.cs” and no Main() method to process.  Instead, the entry for the application is found in “App.xaml.cs”.  There is no entry method here like Main: in order to process the incoming paramters, we need to add a listener to the App_Startup event.  This event will fire prior to the Window class being executed. In order to hook the event up to the application, edit “App.xaml” and add Startup=”App_Startup” to the Application declaration.

The event includes a StartupEventArgs object, which contains a reference to the Args array, so you would simply parse it as desired just like in the Windows Forms Main() method. The difference with WPF is that we do not have a call to the Window class exposed like we do in Windows Forms.  What we do have, in the Window class, is access to the Application object itself.  Microsoft’s sample, downloadable from MSDN, creates a static variable in the App class and populates it in the App_Startup event.  The Window class then accesses the static App variable for its access to the command line arguments.

The sample above parses the values and stores them in a Hashtable (yuck!), so obviously we have some better options, like a generic Dictionary.  Or even better, how about a custom class that holds the values you want?  This would be especially good if some of the values are not strings, or to enforce business rules on the incoming parameters.  I like this approach because it allows all the parsing work to be done outside the Window, leaving the Window to only determine how to use the results.  It just feels better to me since one of our primary goals with WPF is separating layers of responsibility.

If you don’t like the process above, or you really want to handle the parsing inside the Window class, you still have access to Environment.GetCommandLineArgs(), and it works exactly like it does in Windows.Forms.  Again, you can just ignore the 0 index and process the arguments directly.  Oh, and if you are a real glutton for punishment, both methods include the Environment.CommandLine property, a string that represents the complete command line entry.

Debugging Command Line Parameters

I hate trying to navigate through the DOS shell (excuse me: Command Prompt) to find the exe file of my project in order to test command line argurments.  Fortunately, we don’t have to!  If you go to the main menu and follow Projects -> “xxxApplication Properties”, and then click on the Debug tab, you’ll find a box where you can enter the Command Line Arguments you want to test.  As expected, they will be included when the application begins and you can debug their values.

Categories: WPF

WPF Visual State Manager

November 7, 2008 3 comments

Last night at RVNUG, a friend of mine pointed me to The WPF Toolkit. The toolkit is a collection of controls and features that extend the current WPF offering from Microsoft. Chief among these is the DataGrid control, but something more appealing caught my eye: Visual State Manager.

Basically, the VSM is a very easy to use feature of Blend 2 SP1 that supports Silverlight 2. It allows the developer to easily set the visual state of user controls and control templates based on the current state of the control, such as MouseOver and Pressed. I had seen this when I was exploring Silverlight 2 in Blend 2, but I’ve been focusing on WPF and was curious as to why I didn’t have the same functionality I had seen in Silverlight. Of course, now I know: VSM is currently only included as part of Blend 2 for Silverlight 2 development. But, if you install the WPF Toolkit and follow the instructions in the link above to update your Registry, you can gain access to the same basic functionality for WPF Applications.

Using VSM in WPF

Previously, these state changes could be accomplished using Storyboards and Timelines, and then assigning their beginning and ending to Triggers. The Timeline tool in Blend is robust and feature rich, but I think for a non-graphically oriented developer it can be more than a little daunting. And it seems to be overkill for simple animations. That’s where VSM comes in: it greatly simplifies the task of adding small animations to element states.

The Silverlight implementation is very nice and intuitive right out of the box: the states are already defined and all you have to do is activate one and make your changes to the art board. Unfortunately, the current version for WPF is not as straightforward. In WPF, once you have the State manager visible, you have to create the State Groups and define the Visual States you wish to modify. Once I figured out what was going on, this is not painful by any means, but it took some trial and error to get it working right. Don’t forget to add a reference to %Program Files%\WPF\WPF Toolkit\…\WPFToolkit.dll to each project in which you wish to use VSM.  Trust me, it will save you a lot of heartache!

So first things first, we need something that VSM can interact with. Since VSM cannot be applied to the default template of a control, we need to create our own. For this article, I created a button and then created an empty template. Once you create the template, either by ‘edit a copy’ or ‘create empty’, the States Manager will appear under the Triggers Manager on the left hand pane. At this point, the only item visible in the States Manager is Base. You can go ahead and create the default look of your template at this point.

Set up the State Manager pane

To begin with we need a Visual State Group to hold our Visual States. In the Top Border of the States Manager pane on the far right side is a small icon with a plus sign on it. Hovering over it will reveal that this is the “Add state group tool. Pushing it will create a new Visual State Group header under Base. Click on the title (VisualStateGroup) and rename it as you see fit. I’m not sure that the group names matter, but to be on the safe side I followed the same scheme that Silverlight reveals and called my first one “CommonStates”.

Now that we have a group to hold our collection of Visual States, we can start adding states. On the CommonStates header bar is another icon with a plus symbol: this is the “Add state” button, so press it to add a new state. Rename VisualState to the desired state. The state names do matter if we are to get the desired result, so I added three typical states: Normal, MouseOver, and Pressed.

Altered States

Now that we have all the missing pieces defined, we can use them just as we do in Silverlight 2. Clicking on the desired state in the State Manager pane will turn on State Recording [as indicated by the red border around the art board and the header message “State recording is on”]. Now you can easily adjust the display elements of the content to whatever you want them to be at that particular state. A classic example would be brightening a button on MouseOver.

When you are done editing the visual elements, click on Base in the State Manager pane to exit state recording mode. It is important that you do this, because otherwise you could easily alter just a given state when you think you are altering the control template itself. Take it from me, this is very frustrating when you do not receive the results you expect. And then, of course, to correct it you need to back all of your changes out and reapply them outside of state recording mode.

Adding transitions

If you have done all of the above, your button should be changing its visual appearance when you mouse over or press the button. You may think this is the end, but wait, there’s more! Leaving it as above will force the change from one state to another to happen immediately. While we have become accustomed to such UI, it is not the most pleasing effect. Instead, users react much better to very slight, more realistic animations. In other words our users will find our software more appealing if it takes a little time to change from one state to another. These quick, smooth changes from one state to another are very short and simple animations called “Transitions”.

To add a Transition, find the Visual State (such as “MouseOver”) in the State Manager pane and look to the right side of the header bar. There you will find an arrow icon adorned with a plus symbol (notice a pattern developing here?) Click on that and a helper window will appear with a collection of Transitions you can modify. In my case, I chose the two with the ‘*’. The one with the * on the left side indicates the transition from any other state to the selected state, and the one with the * on the right indicates the transition from the selected state to any other state.

Clicking on the desired Transition will add it beneath the selected state. On the Transition you will find a text box that lets you enter the desired amount of time you wish the particular Transition to take. The available range is 0 to 1 second. It doesn’t take much for our Transition to have the desired effect, so try .1 or .2s at first to get the feel for it, then adjust as you desire.

Conclusions

Now when you run your project, you should detect the pleasing effects of Transitions. Overall, I find this much much easier than Storyboards and traditional animations. I’m sure that eventually the tooling for WPF Applications will improve to match what is in Silverlight, but overall it is a minor complaint. I want to thank the CodePlex guys for letting us in on this great secret!

Categories: Blend, WPF

My first real WPF and Blend 2 application

October 21, 2008 Comments off

I’ve been familiar with WPF since December 2006 and the release of C# 3.0, and I’ve had Expression Suite installed for almost a year. While I’ve toyed with it here and there, I have never devoted the time and effort necessary to really begin to become proficient.

However, since last week’s Silverlight 2.0 release, I have been burying myself again in learning new technologies. I finally decided to take the plunge, so I installed Silverlight 2.0, the Visual Studio updates, and upgraded to Expression Suite 2 SP1. I spent a couple of days going through ScottGu’s tutorials and some others on Silverlight.net. I followed along and built the samples, some in Visual Studio and some in Blend.

Most of these have been around for a while, so I’m not claiming any kind of leading edge stuff here. What I wanted to do was to share some of the insights I’ve had in attempting this project.

What’s the big deal

XAML marks a sea change in how user interfaces are developed. The end result of XAML is still .NET objects, and as such they can be created and managed programmaticaly, but the ability to simply describe what you want is very attractive. For a long time, I did not like XAML itself, and one of my reasons for putting off learning WPF was that I wanted to wait until something like Blend made all XAML interaction obsolete. After diving in for a few days, I no longer feel that way, but I’ll share more about that later.

What really makes all this so attractive is the ability to do basically whatever I can imagine for an interface. More importantly, I can do it without a ton of hand coded control drawing, something I never liked doing in the first place. The behavior of a control truly is separate from its presentation, and the presentation can be altered or replaced in any number of ways. In other words, you can achieve some pretty cool effects with a reasonably small effort.

Visual Studio or Blend?

I’ve been having an ongoing discussion with a friend of mine at RVNUG about the usefulness of writing WPF applications within Visual Studio. Having seen some demos and had some training on Blend, I was staunchly in the Blend corner on this one. While you can drag and drop controls in Visual Studio, it takes a lot of hands on XAML coding to get anything more than a rudimentary window up and running. As I mentioned previously, after seeing some XAML presentations I really wanted to avoid that as much as possible, which is what makes Blend so intriguing.

But, having gone through ScottGu’s Silverlight tutorial and building an application in Visual Studio, I have a better appreciation for it now. One thing I do like about using Visual Studio is that it is keyboard centric. As a classic Midrange developer I have always shied away from using the mouse as much as possible, so it appeals to my keyboard-philia. And of course, Intellisense is still the killer feature and makes it much more palatable. Also, as a seasoned and grizzled web developer who still likes the occasional dip into VI and Notepad, it only took a little time with XAML to feel comfortable with what was going on. Anyone familiar with XHTML and CSS should find XAML completely doable. It is, of course, a lot more complex, with numerous options and quirks, but it is still familiar territory.

Now, all that being said, I still prefer Blend 5 to 1 over Visual Studio for Visual XAML development. I have only run into a few things that I couldn’t accomplish easily through Blend, and I’m new enough to it that I still chalk it up to just not knowing the tool well enough. Applying and developing styles is still one of these areas: I so far have not figured out how to do them in Blend, so I revert to XAML editing.

Which brings me to my question of the day: “Should I use Visual Studio or Blend?”  The answer is a resounding “both!” OK, I’m sure you saw that one coming, but let me explain my position. If you are a developer, there is no question that you are going to use Visual Studio. After all, it is our bread and butter, and all the real code will still be developed in our beloved IDE. But designing serious WPF solutions in Visual Studio would be far too painful, even with great Intellisense support. There are simply too many options to have to code them by hand.

It reminds me of my first Windows application: a Java Swing application that I wrote in Wordpad. Believe me, the pain of that experience made me instantly recognize the value of Visual Studio and is largely responsible for my shift to Microsoft technologies. On the same order, as soon as I saw Blend I knew that this was the tool I needed to design good WPF applications. So, for layout and Visual Tree management, use Blend. When you find a problem that you think you must solve using XAML editing, switch over to Visual Studio and take advantage of Intellisense, which Blend does not have.

Quirks

A couple of things so far have jumped out at me. While Blend and Visual Studio do a pretty good job of keeping each other in synch, there are a couple of irregularities.

The first real problem I had was in adding existing projects to my solution in Visual Studio. I started my solution in Visual Studio and then opened it up in Blend to work on the design. Later in the same session, I went back to Visual Studio and added several projects. Now that I had some CLR objects to work with, I wanted to try Data Binding, so I followed one of the online tutorials but no joy. No matter what I did, I could not get Blend to find the objects. Every time I tried, I received a slew of “file could not be located” errors. Finally, I restarted Blend and when I opened my solution, there the missing objects were.

Second, there have been several times when I’m not sure that I am being properly prompted to reload. I could be imagining it, but I feel pretty strongly that I have made changes in one without being prompted by the other to reload them. Perhaps this is just a matter of timing Saves.

Conclusion

Well, I don’t really have any as of yet. I do think that a lot of developers are going to struggle against the designer learning curve, yours truly included. But I think in the long run we will be much better off. So far, I am pleased with my efforts. I like the combination of resources the two applications provide me, and I amd getting more comfortable in deciding which to use for certain scenarios.

I’m not quite ready for a tutorial series, but I will try to share some of my learning with you all as I go. In the meantime, give it a try yourself and let us know what you think. Happy Coding!

Categories: .NET 3.5, Blend, C# 3.0, Expression, WPF

Post Conference Detox

November 16, 2007 Comments off

I am travelling home today, but in between flights I am checking into a few items. First of all, and yes I know most of you are saying “Duh!”, I am checking out MSDN Subscriptions for the first time. See, when we started learning .NET we did not know if it would stick for us not, so the idea of committing to a subscription just wasn’t in the cards. Now, two versions of VS later I think there is no question that we are in .NET to stay.

I’m still waiting for VS2008 to RTM before I download it, but this way I can do it without waiting for CDs or anything like that (not to mention all the other code I get access to). The Visual Studio Professional version of MSDN is $1199 with an annual renewal of $799. Again, a no brainer.

I’m also looking at Microsoft Expression Blend. Preview 2 is out, and supposedly when it goes RTM it will be available on MSDN as well. I think I will go ahead and download the free tria now that XAML makes a lot more sense to me.

So, I have begun detoxing and will be employing these new goodies as soon as possible.? There are a million things floating about in my head.? I actually fell asleep last night thinking of a new WPF layout for a small internal database I started last week. I haven’t been this excited about coding in a long time: thank you Microsoft!

Categories: .NET 3.5, C# 3.0, WPF

Live Blogging VSLive! Austin – Day 2

November 13, 2007 Comments off

Keynote Address “Mapping your way through Microsoft’s Managed Data Access” – Michael Pizzo, Microsoft

10:30am:

The purpose of LINQ is to overcome some of the inherent flaws in Ad Hoc SQL data access from applications.

  • LINQ provides a set of language extensions
  • Integrates Query access as part of the application rather than implemented as Strings
  • Return values are in fact classes complete with strong typing rather than generic DataSets
  • Implements IQueryable to use LINQ over Collections
  • LINQ is available against DataSets, XML, and Entities as well as SQL

LINQ to SQL:

This is going to be the most important part of LINQ. This will essentially allow integration of the SQL Schema into usable objects in the Application.

  • Essentially a Strongly Typed SqlClient
  • Classes map to tables, views, SQL, and other Schema
  • Classes are generated by the LINQ Designer in VS2008 (saw a great demo of this)
  • Allows simple renaming of properties
  • Foreign Keys are implemented as Relationships
  • This means that additional table rows can be read in using Object syntax as opposed to additional SQL
  • Allows Type Inheritance for sub-Schema relationships
  • Can perform better than IDataReader
  • Can use StoredProcedures instead of SQL
  • Uses DataContext objects instead of IDbConnection – be sure to wrap in using statements for proper disposal
  • SQL Results become objects
  • Foreign Keys are available as Collections
  • DataContext has a .Log property for retrieving connection information
  • DataLoadOptions class allows finer control over when and how Related tables are read into the object

LINQ to DataSet:

  • DataSets still have value
  • Disconnected, serializable, etc.
  • LINQ makes filters, joins, projections, cross DataTable and cross Collection queries
  • Supports Typed and Untyped DataSets

ADO.NET Entity Framework:

The Entity Framework allows the Database Schema to be translated into complex Business objects.

  • Object Models are more complex than Schema’s rectangular storage model
  • Enables apps to work with higher level concepts such as relational navigation
  • Supports Type inheritance
  • Built over DataProviders
  • EntityClient is a declarative mapping of model to schema
  • LINQ can run over EntityClient
  • Produces Business objects
  • Provides Change tracking
  • Designers for this built into VS2008

The Future – Astoria:

  • Data Services over the web
  • LINQ/Query/CRUD over the web
  • Delivered as XML
  • Consumed over HTTP
  • LINQ can be used in Silverlight

11:40am update:

Attended “LING: What’s it all about?” by Ken Getz. I was really afraid that after the excellent keynote it would be repetitive, but NOT SO! I got so much out of it, and lots of it is not LINQ specific.

  • LINQ format is From… Where… OrderBy… Select
  • Select is always last, which really throws us SQL users
  • Select is last in order to properly support Intellisense (which unfortunately really only works in VB for now)
  • The From clause includes an item handle and indicates a Data Source
  • Uses implicit variable declarations – in both VB and C#, you can get an object variable to define it’s own type based on return value

Extensions Methods:

  • Add new methods to existing classes without access to the source code
  • Must be Public
  • Must accept a parameter of the type you wish to extend
  • In C#, it must be defined in a Static Class
  • C# uses the this keyword to indicate that this is an extension method
  • Can be used as a Static Class Method or an Instance method

Automatic Properties:

  • For properties that only expose an internal variable, the need to define and use that variable is no longer required
  • Does not require Constructors to update them, but it opens the problem of initializing properties that are not included in any constructor
  • SO – a Constructor can be used that does not actually exist: properties can be indicated on the new statement like so: MyClass c = new MyClass() {prop1 = value, prop2 = value};
  • Which means you can use a Constructor that essentially does not exist

LINQ for Objects:

  • Great for analyzing Collections
  • Takes advantage of Extensions Methods
  • Query class has many built in extensions:Any, All, Average, Where, Concat, Contains, Convert, Count, Distinct, Except, etc. etc.
  • Can use functions in Select clause
  • Functions must supply an expression (called “Lambda Expressions”)
  • Can include Anonymous Methods
  • Expressions can only have one item in and one item out
  • There can only be one expression on a function
  • Example: foreach(Actor a in Actors.Where(x => x.BirthDate.Month == 9))
  • “x” above is the individual object notation, “=>” indicates execute this comparison
  • Can use Anonymous Types – essentially, these are objects created on the fly (like creating columns in SQL Select) and added as a new Type to the resulting objects in the resulting Collection
  • Example: “Select new {NameOfProperty = actor.LastName + “, ” + actor.FirstName}”
  • Use Skip and Take to paginate different rows from within a collection

1:40pm update:

Attended “Styles and Data Templates” given by Bill Hollis. A good follow on from where we left off yesterday, the class got into some of the finer aspects of Templates and Styles. The more I see this stuff, the more I want to smack my head: I’ve had 3.0 installed since last year’s conference, but I’ve never forced myself to spend some time learning any of it. I look at it now and wish I had. But in truth this is the right time to be learning about it: with VS2008 and Blend, the technology is finally beginning to catch up with the theory. This is also the right time for my company given that we are just entering the development stage of a new suite of Applications. But enough rambling, on to the highlights:

  • Styles can be changed on the fly for any Element using the FindResource() method
  • TargetType is used to specify a style for all Elements of the same type en masse (within subsequent scope). This can be applied at any level, where ever a Resource can be defined (which is anywhere)
  • TargetType can only be applied to a single Type (this is not true for named Styles) – it cannot be found and applied to children of a different type
  • You can develop and import ResourceDictionaries to store Resources externally – think reuse, like importing CSS files
  • Styles support inheritance, so you can pull from a common parent and apply additional styles or override styles for specific elements
  • Style precedence is deermined from the element up, so if the element describes and style, then it overrides any named styles or TargetTypes
  • Inheritance accomplished by using “BasedOn={StaticResource parentStyleName}” on the Style definition
  • Styles can be tied to properties (and Events in WPF have reflecting properties, so by extension they can be tied to Events also)
  • DataBinding can be done at the Control or Container level, so you can specify a single Binding for an entire DataTemplate or Panel and then use it in child Elements
  • DataTemplate is like a mini-Window defined in XAML
  • DataTemplate places content in a ContentControl
  • The root Element is usuallya Panel, but can be anything
  • Anything goes regarding layout with a DataTemplate
  • Blend has a DataTemplate editor (why doesn’t VS have some of this stuff?)
  • A DataTemplate can have Triggers that change aspects of its display based on events and properties
  • They can be applied base don individual properties to any level Element

I have not seen it demonstrated, but after the presentation Billy confirmed that he has seen Vista Gadgets built on WPF. Man, the possibilities here are unbelievable. WPF really is the first GUI paradigm shift we’ve since the GUI was created.

3:10pm update – VS2008 Overview:

  • VS is a shell that hosts other Components
  • Because 3.0 and 3.5 build on 2.0, there is distinct support for each of these three frameworks in VS2008
  • 2008 Solution files are a little different than 2005
  • ASP.NET Web Applicaiton projects have AJAX support built in
  • Intellisense can be hidden by holding the CTRL key down (well, not really hidden, but it becomes translucent)
  • Intellisense is expanded and improved in VS2008: supports LINQ
  • JavaScript Debugging – use F9 to set breakpoints
  • Complete access to the Document object tree in debug
  • There is an ImmediateWindow for making and testing on the fly Script changes
  • WCF support is built in to VS2008
  • WPF Designer is built in to VS2008 (but investigate Blend)
  • WPF anchoring is controlled inside the designer window, not the properties grid
  • ClickOnce support enhaned
  • VS2008 also has XSLT debugging
  • XSLT breakpoints can be set in both theXSLT and the Data Source file
  • Web Apps have a Split Screen designer option
  • Support has been added for nested Master Pages

4:20pm update:

Attended a class on “Expression Blend for Developers” by Billy Hollis. Not really a lot of new information, but it did go into more detail and show some more hands on type use of Blend.

  • Blend is part of the Expression Suite, but Blend is included in MSDN. The rest of the suite is really meant for Graphics Designers.
  • Blend is the preferred tool for developing WPF and SilverLight UI.
  • Blend and Visual Studio share the same projects, so when you create a project in Blend you must select the Framework and Language targets even though you cannot develop code in Blend.
  • Blend is designed for Wide Format screens, so that will grant a better user experience than traditional aspect ratios.
  • Blend will execute code written in VS.
  • Grid is the default root element of any new WPF app in Blend, but it can be changed to other Panel types.
  • Grid Columns are better designed in VS than in Blend: the properties grid in VS makes setting column and row information easier while Blend only allows you to approximate sizes by eye on the design surface.
  • Otherwise, Blend is the superior tool for the UI development.
  • XAML editing in Blend does not have Intellisense (but VS does)
  • Blend has visual tools for creating DataTemplates and Styles and can save them as Resources, either for the Application, Windows, or a ResourceDictionary
  • Blend can set up DataBinding using a drop and drag technique

After all I’ve seen, between WPF and Blend, C# 3.5 and LINQ, all I can say is that I am going to have a lot of fun over the next few months.

Post session update:

The last session of the day was on the new Entity Data Model.? The keynote this morning had already hit most of the highlights, but in this session we actually got to see some of the tools and results.? And again, I am very impressed.? The technology is not ready for prime time (which is fitting since it won’t be released until spring), but it has great promise.? The point of it all is to be able to further abstract the database schema from the objects that use it.? EDM is all about abstraction: data mapping rules stored in XML files are how the complexity is managed.

Basically, the objects are defined as you would actually use them, with no regard to how they relate to database schema.? The framework then generates “go between” code to handle CRUD operations.? LINQ is used heavily to interface with the resulting Entities.? This will definitely be a technology to watch.? Here are some final bullets:

  • Can be done in VS2008, but you need to load the ADO.NET Entity Framework and tools separately
  • Provides graphical modeling of databases and Entities
  • The resulting Entities are then used in lieu of the actual DB connection (using the ADO.NET disconnected model).? In other words, you treat data like objects
  • One Entity can update multiple tables seamlessly, and the schema relationships are maintained
  • If the schema changes, must rerun the wizard to regenerate the new Entities. (unless you are a masochist who likes to do things manually)

More to come tomorrow.? Whew, these days can really wear you out!

Categories: .NET 3.5, C# 3.0, LINQ, WPF