次の方法で共有


Showing System Colors Using Data Services Sample

The sample displays a list of the system colors and lets you sort the list in several ways. You can also add new colors to the list and modify properties of the new colors.

This sample demonstrates a specific feature of the Windows Presentation Foundation and, consequently, does not follow application development best practices. For comprehensive coverage of Windows Presentation Foundation (WPF) and Microsoft .NET Framework application development best practices, refer to the following as appropriate:

Accessibility - Accessibility Best Practices

Security - WPF Security

Localization - WPF Globalization and Localization Overview

Performance - Optimizing Performance: Data Binding

Download sample

Building the Sample

  • Install the Windows Software Development Kit (SDK) and open its build environment command window. On the Start menu, point to All Programs, Microsoft Windows SDK, and then click CMD Shell.

  • Download the sample, usually from the software development kit (SDK) documentation, to your hard disk drive.

  • To build the sample from the build environment command window, go to the source directory of the sample. At the command prompt, type MSBUILD.

  • To build the sample in Microsoft Visual Studio 2005, load the sample solution or project file and then press CTRL+SHIFT+B.

Running the Sample

  • To run the compiled sample from the build environment command window, execute the .exe file in the Bin\Debug or Bin\Release folder contained under the sample source code folder.

  • To run the compiled sample with debugging in Visual Studio 2005, press F5.

Remarks

This sample uses the familiar RGB and HSV color codings. It is easy to learn by experimenting with the buttons and sliders. Note that you cannot change the properties of the built-in system colors; you can only change the new colors that you've added with the New Color button.

The sample illustrates two of the paradigms that WPF brings to application design.

  • The treatment of Data and user interface (UI) should be partitioned into separate, relatively self-contained implementations.

  • Most standard UI should be expressed declaratively.

Consistent with these design goals the source of the sample is divided into four parts with a separate file for each:

  • Data-centric code (ColorItem.cs). This code deals with colors using routines that are generalized to facilitate their reuse in other applications that need to deal with system colors. The code is intentionally independent of this particular sample's UI.

  • Application glue (App.xaml). Basic code used to hook the parts of the application together and to get the application started.

  • UI Description (Colors.xaml). Markup specifying the UI and Layout.

  • Application Logic (Colors.xaml.cs). Code in a separate "code-behind" file that implements those features of the application that cannot be done purely declaratively. This includes handlers for buttons, data converters, and so on.

See Also

Other Resources

Data Binding Overview