How do I programmatically interact with template-generated elements? Part II

This post shows you how to find a named element within a DataTemplate.   In Part I, we discussed how to find a named element within a ControlTemplate. That was fairly simple; you’d call Template.FindName on the control that the ControlTemplate has been applied to. But if the template is a DataTemplate, then the scenario…

24

Data Validation in 3.5

A cool new feature in the Data area in 3.5 is the support for IDataErrorInfo. Let’s take a look at the data validation model in 3.5 by starting with a memory refresher of that in 3.0. We end with a section that discusses how to choose between the different approaches. 3.0 Validation Model In 3.0,…

16

WPF Basic Data Binding FAQ

Through talking to people and monitoring both internal and external forums, I have compiled a list of questions people often have when first learning about WPF data binding. If you have any questions, please leave a comment and let me know!   What is target and what is source? In WPF, you typically use data…

15

How do I programmatically interact with template-generated elements? Part I

You may have a scenario that requires you to find an element within a ControlTemplate. To do that, you use Template.FindName.   Say you have a simple ControlTemplate for a Button, like the following:       <Style TargetType=“{x:Type Button}“>       <Setter Property=“Template“>         <Setter.Value>           <ControlTemplate TargetType=“{x:Type Button}“>             <Grid Margin=“5“ Name=“grid“>               <Ellipse Stroke=“DarkBlue“…

12

Specifying the Selection Color, Content Alignment, and Background Color for items in a ListBox

This post covers some tips and tricks that people frequently ask concerning specifying the appearance of a ListBox.  Here’s some things that someone, somewhere, might find useful:   Specifying the Selection Color   If you’ve ever tried the following, you know it won’t work.         <Style TargetType=”ListBoxItem”>         <Style.Triggers>           <Trigger Property=”IsSelected” Value=”True”>            …

10

XAML FlowDocument to HTML Conversion Prototype

XAML FlowDocuments and HTML have some things in common. But they also have some distinct differences that makes writing a conversion utility tricky. A well written XSLT could potentially process XHTML input and generate FlowDocument content… But this pre-supposes well-formed HTML in the first place. I’ve tried to go down this road on a few…

10

Maximizing WPF 3D Performance on Tier-2 Hardware

As people use the Windows Presentation Foundation to build more 3D controls and include 3D scenes in their applications, they’ve been asking questions about how to optimize performance.  Several members of the WPF 3D team have provided a list of 3D classes and properties that have performance implications, along with recommendations for optimizing performance when…

9

Best Practices for Globalization and Localization in WPF

You can make the most of the globalization and localization functionality that is built into Windows Presentation Foundation by following the UI design and localization-related tips that this section provides. Best Practices for WPF UI Design When you design a Windows Presentation Foundation–based UI, consider implementing these best practices: Write your UI in XAML; avoid…

9

Experiments with WindowChrome

In July, the Microsoft Ribbon for WPF was released. Hopefully you saw the announcements from the WPF Team and on Pete Brown’s blog, and have already downloaded the Ribbon. A little bonus that you get with the Ribbon is the WPF Shell Integration Library and documentation for it on MSDN. This library includes the WindowChrome…


Custom Window Chrome in WPF

Guest post by Joe Castro, WPF product team developer This document covers the design and some implementation details of getting WPF windows wrapped in custom chrome. Currently WPF supports standard windows, with an icon, title-text, and caption buttons, as well as borderless windows, which when combined with transparency allow arbitrary top-level shapes but the application…

8