Welcome to MSDN Blogs Sign in | Join | Help

Chart Controls for WPF ship in the Toolkit

We posted previously about the development of the WPF chart controls.  With the release of the June WPF Toolkit you now have the controls at your fingertips.  You can make bar, pie, bubble, scatter and line graphs.   Check out this blog post for details!

image Here’s the code for the image above:

Add a reference to the System.Windows.Controls.DataVisualization.Toolkit assembly in your project, add the namespace for the Charting controls, add a chart in XAML and add some data in code behind.  Instant pie chart!

XAML

<Window x:Class="WpfChartControl.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"

        xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"

    Title="Window1" Height="300" Width="300">

    <Grid>

        <charting:Chart x:Name="chart" Width="350" Height="250">

            <charting:Chart.Series>

                <charting:PieSeries ItemsSource="{Binding}"

                    DependentValuePath="Value"

                    IndependentValuePath="Key"

                    Title="Pet Preference" IsSelectionEnabled="True" />

            </charting:Chart.Series>

        </charting:Chart>

    </Grid>

</Window>

C#

chart.DataContext = new KeyValuePair<string, int>[] {

                                    new KeyValuePair<string, int>("Dog", 30),

                                    new KeyValuePair<string, int>("Cat", 25),

                                    new KeyValuePair<string, int>("Rat", 5),

                                    new KeyValuePair<string, int>("Hampster", 8),

                                    new KeyValuePair<string, int>("Rabbit", 12) };

VB

chart.DataContext = New KeyValuePair(Of String, Integer)() _

                                {New KeyValuePair(Of String, Integer)("Dog", 30), _

                                 New KeyValuePair(Of String, Integer)("Cat", 25), _

                                 New KeyValuePair(Of String, Integer)("Rat", 5), _

                                 New KeyValuePair(Of String, Integer)("Hampster", 8), _

                                 New KeyValuePair(Of String, Integer)("Rabbit", 12)}

 

WPF and Silverlight Designer for VS 2010 featured at WindowsClient.NET

We’re featured over at WindowsClient.NET on the new WPF and Silverlight Designer for Visual Studio 2010 page.

There are new walkthroughs and videos for creating your first WPF and Silverlight applications, as well as tutorials for setting up the designer to your liking.

Visual Studio 2010 layout

And don’t forget to point your RSS aggregators to the new RSS feed!

Code sample for the WPF DataGrid.CellStyle topic

At the deadline for Visual Studio 10 Beta 1 content complete, I was madly trying to check in art and code for the DataGrid APIs.  I thought I got it all in but failed to click submit to actually finish uploading the code for CellStyle.  So if you are interested, here is a little sample code.  Using styles in DataGrid is an amazingly powerful way to accomplish a lot without writing much code. 

The following example uses a trigger to change the Background color of a DataGridCell when the cell is selected.

        <DataGrid Name="DG1" ItemsSource="{Binding}" SelectionUnit="Cell" >

            <DataGrid.CellStyle>

                <Style TargetType="DataGridCell" >

                    <Style.Triggers>

                        <Trigger Property="IsSelected" Value="True">

                            <Setter Property="Background" Value="SeaGreen"/>

                        </Trigger>

                    </Style.Triggers>

                </Style>

            </DataGrid.CellStyle>

        </DataGrid>

The ItemsSource is an ObservableCollection of Animal objects:

public class Animal

        {

            public Animal()

            {

            }

 

            public Animal(string name)

            {

                Name = name;

            }

 

            public string Name { get; set; }

 

        }

This code produces the following output.

A selected cell with a green background

 

Posted by mparsons | 2 Comments

TestApi v.0.2 Released!

The second preliminary version of TestApi, the testing API library has been released. TestApi is a library of test and utility APIs that you can use to test WPF, Windows Forms, .Net Framework, and Win32 applications. You can see Ivo's post for more information.

You can get the TestApi from http://codeplex.com/testapi.

 --Nitya.

Posted by niravi | 1 Comments

Offline Beta WPF .Net Framework 4 documentation

Want fast MSDN docs that are scoped only for beta WPF and can be accessed without an internet connection?

Download the WPF CHM.

BTW, if your download is slow, it's an 108 MB file coming from my machine at home. Needless to say this is an unfunded project so any comments on the good/bad value of this CHM is appreciated.

IMPORTANT! If you open the CHM and cannot view content, do the following to resolve the issue:
- Right-click the CHM file, and then click "Properties".
- Click "Unblock".
- Double-click the .chm file to open the file.

Sam

Posted by snoutholder | 4 Comments

.NET Framework 4 and VS Beta1 docs are posted

Docs for .NET Framework 4 Beta 1, Windows Presentation Foundation (WPF), and Visual Studio 2010 Beta1 are now available at MSDN.

 

data binding builder

The new data binding builder in the WPF Designer and the Silverlight Designer

You’ll see the strong focus on line-of-business (LOB) applications in this release. In particular, binding WPF and Silverlight apps to enterprise data sets is supported in the WPF Designer: see Binding WPF Controls to Data in Visual Studio and Walkthrough: Creating a Data Binding by Using the WPF Designer for details. You’ll notice other improvements, including new LOB controls such as DataGrid, DatePicker, and  Calendar.

 

DataGrid with all four default column types

DataGrid displaying an AdventureWorks data set

 

And consider spicing up your WPF and Silverlight animations with the EasingFunction classes. They pack a lot of functionality into a tight package.

 

BounceEase EasingMode graphs.

BounceEase easing function

 

Understanding Performance in your WPF Application

I just finished reviewing a document for using the WPF Performance Profiling Tools and I have to say it looks like a lot of fun.  I'm ready to start hooking up all my sample apps just to see what happens.

I know perf is an issue everyone cares about and if you haven't seen the performance tools before, you should check them out.  The tools help you figure out where you are spending the most CPU/GPU and include lots of cool visualizations so you can see the problems in your running application.  And if you want to know more about improving the performance of your WPF application, don't forget to check the section in our docs about Optimizing WPF Application Performance.  This section includes topics on performance issues for layout, graphics, data binding, controls, text and more.  In addition, you can check Jossef's blog for regular perf tips.  And as always, if you can't find the information you need to write your application, drop us a line. 

-Margaret

 

Posted by mparsons | 1 Comments
Filed under: ,

A Twitter Application in WPF

DigiFlare has released the beta of a new WPF application called DigiTweet. DigiTweet is a desktop application for users of Twitter. The application is built completely using .NET technologies and takes particular advantage of the power of WPF (Windows Presentation Foundation) which is the part of .NET that enables developers to build powerful user experiences on Windows. Additionally, DigiTweet will be implementing several Windows 7 specific features in the coming weeks. You can download and experiment with DigiTweet at http://www.digitweet.com and please visit the DigiTweet website in the coming weeks as some fantastic new features come online. DigiFlare has also released all the source code and assets so developers around the world can learn how to light up their applications for Windows Vista and Windows 7.

clip_image002

Here are some of the current and upcoming features of DigiTweet:

Beta Features (Available Now):

     - 100% WPF and .NET!

     - Create, view and send Tweets

     - TinyURL and Twitpic support

     - View all Tweets, Replies, Direct Messages in a rich Dashboard view

Beta 2 Features in Production (Available April 15th):

     - Friends List

     - Search Panes (A favorite and high demand feature found in some other twitter applications)

     - Plus A bunch of other secret features in development!

Additional Release Features Planned for end of April:

     - Favorites

     - Windows 7 Taskbar Enhancements and Jumplists

VantagePoint Controls for Silverlight

You may have seen us blog about the excellent VantagePoint WPF controls from our friends at Mobiform. Happily, I just got a comment from Patrick Barker alerting me to the new VantagePoint Controls for Silverlight, which adds some sleek UI to your Silverlight apps:

 

VantagePoint Dashboard 

Posted by jgalasyn | 0 Comments

More fun with DataGrid

Here’s another DataGrid sample using the WPF Toolkit.  It includes

  • Creating templates for DataGridTemplateColumn
  • Binding to DataGridComboBoxColumn
  • Alternating row colors

Here’s an image of what the code looks like running:

DataGridColumnBlog2

To create the Date Published column, I used the DataGridTemplateColumn and bound the CellTemplate to a custom DataTemplate. 

<!--DataTemplate for Published Date column defined in Grid.Resources --> 

<Grid.Resources>

 

<DataTemplate x:Key="DateTemplate" >

  <StackPanel Width="20" Height="30">

   <Border Background="LightBlue" BorderBrush="Black" BorderThickness="1">

    <TextBlock Text="{Binding PublishDate, StringFormat={}{0:MMM}}" FontSize="8" HorizontalAlignment="Center" />

   </Border>

   <Border Background="White" BorderBrush="Black" BorderThickness="1">

    <TextBlock Text="{Binding PublishDate,StringFormat={}{0:yyyy}}" FontSize="8" HorizontalAlignment="Center" />

   </Border>

  </StackPanel>

</DataTemplate>

...

</Grid.Resources>

 

<!--Define the custom column that shows the published date-->

<toolkit:DataGrid ...>

...

<toolkit:DataGridTemplateColumn Header="Date Published" CellTemplate="{StaticResource DateTemplate}" />

...

<toolkit:DataGrid ...>

It took me a while to figure out how to get binding to the enumeration correct on the CombBoxColumn, but eventually with the help of blog posts from Bea Stollnitz and Vincent Sibal, I was able to put it all together.

<!--Get the values of the MusicCategory enum to populate the ComboBox-->

<Grid.Resources>

...

<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type core:Enum}" x:Key="myEnum">

   <ObjectDataProvider.MethodParameters>

      <x:Type TypeName="local:MusicCategory" />

   </ObjectDataProvider.MethodParameters>

</ObjectDataProvider>

</Grid.Resources>

 

<!--Define the DataGridComboBoxColumn and bind the ItemsSource and SelectedItem -->

<toolkit:DataGrid ...>

...

   <toolkit:DataGridComboBoxColumn Header="Category" SelectedItemBinding="{Binding Category}" ItemsSource="{Binding Source={StaticResource myEnum}}" />

</toolkit:DataGrid ...>

 

Finally the alternating row colors is pretty straight forward but I wanted to show using an AlternationCount of 3.  If you want to get fancy with more colors, check out this blog post from Jaime Rodriguez.  He shows how to use a style with triggers to set the row background based on AlternationIndex in addition to a lot of other useful info on styling DataGrid.

<toolkit:DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="False" AlternationCount="3" AlternatingRowBackground="LightBlue" RowBackground="SkyBlue">

You can get the full code samples (VB and C#) from here.

-Margaret

Posted by mparsons | 1 Comments

WPF Toolkit March 2009 Update is posted

Here’s the official word from the WPF Tree Services & Controls Team:

We shipped some great new updates to the WPF Toolkit and WPF Futures on Codeplex earlier this week.  These included an updated version of the WPF Toolkit with over 20 high-priority bug fixes for DataGrid, DatePicker, & Calendar, and also a package of WPF Themes (matching those shipped with the Silverlight Toolkit) as a new addition to the WPF Futures.  We’ve also added a pointer to David Anson’s blog post with a preview of the WPF Chart Controls which are being written by the Presentation Platform Controls (PPC) team (the team who produces the Silverlight Toolkit).

Don’t miss the WPF Chart Controls. This is some sweet, sweet sugar:

 

ChartBuilder on Silverlight

 

Silverlight 3 Beta unveiled today at MIX ‘09

Don’t miss the live stream from MIX ‘09.

Here’s the official word:

Today, Microsoft Corp. unveiled Silverlight 3 Beta, a preview of the most powerful platform for creating and delivering Rich Internet Applications (RIAs) and media experiences on the Web.  This third version continues Silverlight’s track record of rapid innovation by introducing more than 50 new features, including support for running Silverlight applications out of the browser, dramatic video quality and performance improvements, and features that radically improve developer productivity. Combined with the continued innovation in our world-class tools for designers and developers - Visual Studio and Expression Blend - Silverlight 3 empowers more than 6 million .NET developers to create cutting-edge RIAs and media experiences.  With Silverlight, RIAs are now first-class citizens on any computer.

clip_image002

Features of Silverlight 3 Beta
Fully supported by Visual Studio and Expression Blend, highlights of new features and functionality of Silverlight 3 include: major media enhancements, out of browser support allowing Web applications to work on the desktop; significant graphics improvements including 3D graphics support, GPU acceleration and H.264 video support; and many features to improve RIA development productivity. Also, in order to fully integrate all the .NET developer tools, Visual Studio 2008, Visual Studio 2010 and Visual Web Developer Express will support a fully editable and interactive designer for Silverlight. New features in Silverlight 3 include: (Too many to list here! Go watch the live stream from MIX ‘09.)

clip_image002[4]

 

 

The VisualStateManager and Triggers

 

Silverlight introduced the Visual State Manager, which makes it easier for control template authors to specify the appearance of a control depending on its visual state.  The WPF Toolkit  ships a Visual State Manager, and the next version of WPF will include the VSM as well.   The introduction of the VisualStateManager has understandably led to questions about when  to use the VSM instead of triggers and when triggers are appropriate. This blog post attempts to address that question; more thorough discussions about how to use the VisualStateManager are elsewhere.

 

The VisualStateManager supports the parts and states model, which is a way for control authors to formalize what visual states should be in a control template.  The VisualStateManager enables control authors to manage the states of a control and provides a way for designer tools such as Microsoft Blend to support customizing the control's appearance according to its visual state.  Before the parts and states model was introduced, it was common for control template authors to use triggers to change a control's appearance when it changed visual states.  The following control template uses triggers to change the button's border color when  the mouse is over it or when it is pressed.

 

 

              <ControlTemplate TargetType="Button">

                <Grid>

                  <Ellipse Fill="{TemplateBinding BorderBrush}"/>

                  <Ellipse x:Name="ButtonShape" Margin="5" Fill="{TemplateBinding Background}"/>

                  <ContentPresenter HorizontalAlignment="Center"

                            VerticalAlignment="Center"/>

                </Grid>

 

                <ControlTemplate.Triggers>

                  <Trigger Property="IsMouseOver" Value="True">

                    <Setter Property="BorderBrush" Value="Cyan"/>

                  </Trigger>

                  <Trigger Property="IsPressed" Value="True">

                    <Setter Property="BorderBrush" Value="Red"/>

                  </Trigger>

                </ControlTemplate.Triggers>

              </ControlTemplate>

 

In this model, there is no formal agreement about what the visual states are, there are just some properties defined on a control that can be used to change the control's appearance.  A control that follows the parts and control model proactively communicates its visual states to control template authors.  When a control uses the VisualStateManager to change its visual states, it expects that the ControlTemplate uses the VisualStateManager to specify the control's appearance for a given visual state.  The control template author can also customize transitions between visual states by using VisualTransitions.  VisualTransitions enable control template authors to fine-tune an individual transition by changing the times and durations of individual property changes and even animate new properties not mentioned in either state.    The following example uses the VisualStateManager to specify the changes in the control's appearance instead of triggers.

 

              <ControlTemplate TargetType="Button">

                <Grid>

                  <VisualStateManager.VisualStateGroups>

                    <VisualStateGroup x:Name="CommonStates">

 

                    <VisualStateGroup.Transitions>

                        <!--Take one half second to transition to the MouseOver state.-->

                        <VisualTransition To="MouseOver" GeneratedDuration="0:0:0.5" />

                      </VisualStateGroup.Transitions>

 

                      <VisualState x:Name="Normal"/>

                      <VisualState x:Name="MouseOver">

                        <Storyboard>

                          <ColorAnimation Duration="0" Storyboard.TargetName="borderColor" Storyboard.TargetProperty="Color" To="Cyan"/>

                        </Storyboard>

                      </VisualState>

                      <VisualState x:Name="Pressed">

                        <Storyboard>

                          <ColorAnimation Duration="0" Storyboard.TargetName="borderColor" Storyboard.TargetProperty="Color" To="Red"/>

                        </Storyboard>

                      </VisualState>

                    </VisualStateGroup>

                  </VisualStateManager.VisualStateGroups>

                  <Ellipse>

                    <Ellipse.Fill>

                      <SolidColorBrush x:Name="borderColor" Color="Black"/>

                    </Ellipse.Fill>

                  </Ellipse>

                  <Ellipse x:Name="ButtonShape" Margin="5" Fill="{TemplateBinding Background}"/>

                  <ContentPresenter HorizontalAlignment="Center"

                            VerticalAlignment="Center"/>

                </Grid>

              </ControlTemplate>

 

The control uses the VisualStateManager to change visual states by calling VisualStateManager.GoToState.  When that occurs, the VisualStateManager appropriately stops and starts the storyboards in the VisualState and VisualTransition objects so that the button's appearance appropriately changes visual states.  Therefore, there is a distinct separation of responsibilities:  the control author specifies what the visual states of a control are and determines when a control goes into each visual state;  the template author specifies what the control looks like in each visual state.

 

Triggers aren't dead in WPF, though. You can use triggers to change the appearance of a control for properties that don’t correspond to a visual state.  For example, the Button has a IsDefault property, but there is no corresponding visual state on Button.  A control template author might want to specify the appearance of the button depending on IsDefault’s value, though, so this is a case of where using a trigger is appropriate.  The following example repeats the previous example and adds a trigger to specify the button's appearance depending on the value of IsDefault.

 

              <ControlTemplate TargetType="Button">

                <Grid>

                  <VisualStateManager.VisualStateGroups>

                    <VisualStateGroup x:Name="CommonStates">

 

                    <VisualStateGroup.Transitions>

                        <!--Take one half second to transition to the MouseOver state.-->

                        <VisualTransition To="MouseOver" GeneratedDuration="0:0:0.5" />

                      </VisualStateGroup.Transitions>

 

                      <VisualState x:Name="Normal"/>

                      <VisualState x:Name="MouseOver">

                        <Storyboard>

                          <ColorAnimation Duration="0" Storyboard.TargetName="borderColor" Storyboard.TargetProperty="Color" To="Cyan"/>

                        </Storyboard>

                      </VisualState>

                      <VisualState x:Name="Pressed">

                        <Storyboard>

                          <ColorAnimation Duration="0" Storyboard.TargetName="borderColor" Storyboard.TargetProperty="Color" To="Red"/>

                        </Storyboard>

                      </VisualState>

                    </VisualStateGroup>

                  </VisualStateManager.VisualStateGroups>

                  <Ellipse>

                    <Ellipse.Fill>

                      <SolidColorBrush x:Name="borderColor" Color="Black"/>

                    </Ellipse.Fill>

                  </Ellipse>

                  <Ellipse x:Name="defaultOutline" Stroke="{TemplateBinding Background}" StrokeThickness="2" Margin="2"/>

                  <Ellipse x:Name="ButtonShape" Margin="5" Fill="{TemplateBinding Background}"/>

                  <ContentPresenter HorizontalAlignment="Center"

                            VerticalAlignment="Center"/>

                </Grid>

                <ControlTemplate.Triggers>

                  <Trigger Property="IsDefault" Value="False">

                    <Setter TargetName="defaultOutline" Property="Stroke" Value="Transparent"/>

                  </Trigger>

                </ControlTemplate.Triggers>

              </ControlTemplate>


The IsMouseOver and IsPressed properties on Button are still available, but  you shouldn’t create triggers against them to change the button's appearance.  That doesn't mean that those properties aren't useful, though.  Those properties can still be used by application authors to check the control's visual state in code, and control authors should continue to define properties for visual states even when they use the VisualStateManager to transition between their visual states.

Tip: Invoking Blend from Visual Studio

So you’re using the WPF Designer to build your slick UI, and you realize you need to go to Expression Blend for some high-end resource authoring. Although Blend lets you invoke VS with a quick gesture (right-click on the solution and click Edit in Visual Studio), going the other way isn’t quite as convenient.

Until now.

Add Blend to Tools|External Tools. Set the Arguments and Initial directory fields as shown in the following screenshot.

 

clip_image002

Blend appears on your Tools menu. 

Blend on VS menu

Now Blend is just one gesture away!

More Posts Next page »
 
Page view tracker