How can I create an Image Reflection in WPF without having to hard-code the width and height?

Reflecting another visual in WPF is typically done using a VisualBrush and a ScaleTransform to “flip” the content upside down, as shown in this nice example on xamlog. In order to perform the “flip” the ScaleTransform needs the centre about which this should occur. Unfortunately the centre position of an element is not directly exposed via a property, so the net result of this is that for simple reflections (where you know the size of the source) you typically end up hard-coding the centre of the transform in your XAML . »

Author image

How Can I Create a WPF Animation in a Single Line of Code?

Creating WPF animations in Xaml requires a fair amount of mark-up, and can be somewhat daunting to write by hand. Fortunately animations done in code can be created much more simply (however you do lose the "declarative" way of specifying when animations fire that markup allows). Here is a simple window which contains a single button child element. The hilighted C# code which is executed when the window has loaded animates the height of the button from 25 units to 150 units in 1 second. »

Author image

What do I need to install to get started building WPF applications with WPF Release Candidate 1?

The most recent release of WPF is Release Candidate (RC) 1 - released on the 1st of September 2006. This release is a great milestone for the WPF team, and an important step towards the final release at the end of this year/early next year. To begin developing WPF applications for Windows Server 2003 or Windows XP SP2 you need to download the .NET Framework 3.0 run-time components RC1 (WPF is a part of a larger package of new components for windows called .NET 3.0). »

Author image

New WPF XBAP launch screen for RC1

The default lauch screen for WPF XBAP applications has changed recently (I believe for RC1). This is what your users will see (hosted inside IE) when your XBAP application is being downloaded for the first time. »

Author image

Two WPF Titles from APress

APress have announced two upcoming WPF titles which are available for pre-order from Amazon. The first is Foundations of WPF which is scheduled for release towards the end of November this year, and will be around 400 pages long. It will be devided into three sections covering "WPF in context", deeper dives into relevant areas of WPF and finally real-world perspectives on building WPF applications. The second is Pro WPF scheduled for release in late January and weighing in at 800 pages. »

Author image

How Can I Create a Border Where Only Some Corners are Rounded in WPF?

A recent post in the WPF forums asked this very question. Fortunately it is possible to create a border in WPF and specify a different radius for each corner as a comma-separated list, rather than specifying a single corner-radius. Xaml Code (July CTP) <Window x:Class="BorderCornerRadius.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="BorderCornerRadius" Height="200" Width="300" Background="#58290A" > <Border BorderBrush="#feca00" CornerRadius="0,10,20,40" BorderThickness="2" Height="100" Width="200" /> </Window> This produces the following UI »

Author image

How can I emulate the Glossy Appearance of the iTunes 'now playing' Information

In a comment on our previous post on creating glossy-looking items in WPF Jason asks how to emulate the glossy "now playing" section in apple's iTunes MP3 player. Although we don't want to condone the use of Macs, or any apple software on Windows we were prepared to grant Jason's request. Using these iTunes screen-shots as our starting point this is what we came up with. iTunes "now playing" WPF »

Author image

How Can I Create a Glossy Appearance for Elements in WPF?

Glossy, highly reflective-looking UIs are currently quite popular. While there are many ways you can suggest a reflective surface using gradients and hilights, some of the simpler effects are often the best. Here is a simple approach that uses two rectangles placed on top of eachother inside a grid, which gives a nice reflective appearance. Xaml Code (Jul 2006 CTP) <Page xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/presentation " xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x=" http://schemas.microsoft.com/winfx/2006/xaml " Background="#785429" > »

Author image

What do I need to install to get started building WPF applications with the July 2006 CTP?

The most recent release of WPF is the July CTP - released on the 18th of July 2006. This CTP is a little different to previous WPF CTPs in that the extensions for Visual Studio 2005 to build WPF projects with the CTP have not been released. We'll suggest some work-arounds for this below, but if you're new to WPF and not so concerned with using the latest release you might be better suited to the June CTP. »

Author image

How can I allow users to edit text in a ComboBox in WPF?

The ComboBox in WPF allows users to select an item from the list, but by default does not allow them to edit the text in the combo box. The ComboBox control in Windows Forms on the other hand by default does allow users to enter "free text" into the combo box, in addition to selecting items from the list. In Windows Forms this behavior can be changed, removing the "free text" facility by setting the confusingly named DropDownStyle property to DropDownList. Can we do the opposite in WPF and allow users to edit the text?

Fortunately you can do this in WPF easily by setting the IsEditable property to True as shown below.

Xaml Code (June 06 CTP)
<Window x:Class="LearnWPF.EditableComboBox.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="LearnWPF.EditableComboBox" Height="300" Width="300"
    >
  <Window.Resources>
    <XmlDataProvider x:Key="items" XPath="//item">
      <x:XData>
        <items >
          <item>01</item>
          <item>02</item>
          <item>03</item>
        </items>
      </x:XData>
    </XmlDataProvider>
  </Window.Resources>
    <Grid>
      <ComboBox IsEditable="True" DataContext="{StaticResource items}"
                ItemsSource="{Binding}"/>
    </Grid>
</Window>

Its worth noting that while this change may be simple to make in the Xaml it may also require some changes in your C# or VB.NET application code - you may need to handle more than the SelectionChanged event on the combo box (since users may start entering values outside the range of values in the list and the SelectionChanged will cease to fire). You also can no longer rely on the SelectedValue and SelectedItem properties of the combo box having a non-null value.

»

Author image