Christian Moser's WPF Tutorial.net News and tutorials around the Windows Presentation Foundation en http://www.wpftutorial.net Sat, 13 Mar 2010 21:01:00 +0100 Wrap Panel moc@zuehlke.com (Christian Moser) <h1>Wrap Panel</h1> <img src="images/wrapPanel.PNG" style="padding-left: 50px;"> <h2>Introduction</h2> <p>The wrap panel is similar to the <a href="StackPanel.html">StackPanel</a> but it does not just stack all child elements to one row, it wraps them to new lines if no space is left. The <code>Orientation</code> can be set to <code>Horizontal</code> or <code>Vertical</code>.</p> <p>The WrapPanel can be used to arrange tabs of a tab control, menu items in a toolbar or items in an Windows Explorer like list. The WrapPanel is often used with items of the same size, but its not a requirement.</p> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;WrapPanel</span> <span style="color: #ff0000;">Orientation</span>=<span style="color: #0000ff;">&quot;Horizontal&quot;</span><span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Button</span> <span style="color: #ff0000;">Content</span>=<span style="color: #0000ff;">&quot;Button&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Button</span> <span style="color: #ff0000;">Content</span>=<span style="color: #0000ff;">&quot;Button&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Button</span> <span style="color: #ff0000;">Content</span>=<span style="color: #0000ff;">&quot;Button&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Button</span> <span style="color: #ff0000;">Content</span>=<span style="color: #0000ff;">&quot;Button&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Button</span> <span style="color: #ff0000;">Content</span>=<span style="color: #0000ff;">&quot;Button&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/WrapPanel<span style="color: #800000;">&gt;</span></span></span> </pre></div> http://www.wpftutorial.net/WrapPanel.html Sat, 13 Mar 2010 21:01:00 +01002010-03-02 11:01:47 Install the Development Tools moc@zuehlke.com (Christian Moser) <h1>WPF Development Tools</h1> <p>Microsoft provides two development tools for WPF applications. One is <b>Visual Studio</b>, made for developers and the other is <b>Expression Blend </b>made for designers. While Visual Studio is good in code and XAML editing, it has a rare support for all the graphical stuff like gradients, template editing, animation, etc. This is the point where Expression Blend comes in. Blend covers the graphical part very well but it has (still) rare support for code and XAML editing.</p> <p>So the conclusion is that you will need both of them.</p> <h2>Microsoft Visual Studio 2010</h2> <p>Visual Studio is the tool for developers to develop WPF applications. It includes a graphical designer for WPF since version 2008. If you're using Visual Studio 2005 you can install an add-on that enables you to develop WPF applications.</p> <p>Microsoft provides a free Express Edition of Visual Studio that also includes the WPF designer. You can download it from the following URL</p> <a style="padding-left: 10px;" href="http://www.microsoft.com/express/Express-2010/" class="external">Download Microsoft Visual C# 2010 - Express Edition</a><br/> <br/> <img style="padding-left: 200px;" src="images/v2_vs2008.jpg"/> <br/> <h2>Microsoft Expression Blend 3 + Sketch Flow</h2> <p>Expression Blend is the tool for designers. It's part of the Expression Studio, a new tool suite from Microsoft especially created for user experience designers. Blend covers all the missing features of the Visual Studio designer like styling, templating, animations, 3D graphics, resources and gradients.</p> <p>In the latest Version it also includes a powerful prototyping tool called SketchFlow. Expression Blend can open solution files created by visual studio. </p> <a style="padding-left: 10px;" href="http://www.microsoft.com/Expression/try-it/Default.aspx#PageTop" class="external">Download Microsoft Expression Blend 3</a><br/> <br/> <img style="padding-left: 200px;" src="images/v2_blend.jpg" /> <br/> <h2>Other useful tools</h3> <ul> <li><a href="http://blois.us/Snoop/">Snoop (Inspect the Visual Tree of running WPF applications)</a></li> <li><a href="http://karlshifflett.wordpress.com/mole-for-visual-studio/">Mole (Data Visualizer for Visual Studio</a></li> <li><a href="http://karlshifflett.wordpress.com/xaml-power-toys/">XAML Power Toys</a></li> <li><a href="http://windowsclient.net/wpf/perf/wpf-perf-tool.aspx">WPF Performance Suite</a></li> </ul> http://www.wpftutorial.net/wpfdevtools.html Sat, 13 Mar 2010 21:01:00 +01002010-03-02 00:34:15 Adjust the Frame Rate moc@zuehlke.com (Christian Moser) <h1>How to control the frame rate for WPF animations</h2> <p>Animations are very cool, but they can cause a high CPU load. One reason could be a missing hardware acceleration due to a old graphics adapter or a software rendering constraint. Another reason could be the the high frame rate of animations that is set to <b>60 fps</b> by default. </p> <p>You can easily lower the framerate for all animations by overriding the <code>DesiredFrameRate</code> property of the timeline. Just add the following code to your project and play around with the setting to find a good tradeoff between performance and aesthetic.</p> <div class="codeblock"><pre class="csharp csharp" style="font-family: courier new,courier,monospace;"> Timeline.<span style="color: #0000FF;">DesiredFrameRateProperty</span>.<span style="color: #0000FF;">OverrideMetadata</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #0000ff; font-weight: bold;">typeof</span></a><span style="color: #000000;">&#40;</span>Timeline<span style="color: #000000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #0000ff; font-weight: bold;">new</span></a> FrameworkPropertyMetadata <span style="color: #000000;">&#123;</span> DefaultValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">30</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>; </pre></div> <p>Or you can set the framerate individually for each animation in XAML, using the following code:</p> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;DoubleAnimation</span> Storyboard.<span style="color: #ff0000;">TargetProperty</span>=<span style="color: #0000ff;">&quot;Opacity&quot;</span> <span style="color: #ff0000;">Duration</span>=<span style="color: #0000ff;">&quot;0:0:0.5&quot;</span> </span> <span style="color: #800000;"> <span style="color: #ff0000;">From</span>=<span style="color: #0000ff;">&quot;1.0&quot;</span> <span style="color: #ff0000;">To</span>=<span style="color: #0000ff;">&quot;0.5&quot;</span> Timeline.<span style="color: #ff0000;">DesiredFrameRate</span>=<span style="color: #0000ff;">&quot;30&quot;</span> <span style="color: #800000;">/&gt;</span></span> </pre></div> http://www.wpftutorial.net/FrameRate.html Sat, 13 Mar 2010 21:01:00 +01002010-03-02 00:31:02 Home moc@zuehlke.com (Christian Moser) <table cellpadding="0" cellspacing="0"> <tr> <td style="width: 511px; padding-bottom: 20px; vertical-align: top;"> <h1>Welcome to the WPF Tutorial</h1> <img src="images/title.jpg" style="width: 400px; height: 349px; padding-left: 30px;" /> <p style="padding-top: 20px; padding-right: 10px; padding-left: 0px;">Welcome to my website about the Windows Presentation Foundation. The tutorials will show you how to create the next generation user experience. I hope you will get amazed by the possibilities of this fascinating technology.</p> </td> <td rowspan="2" style="padding-left: 30px; margin-top: 10px; vertical-align: top; border-left: #eeeeee 1px solid;" > [tipofday] [popular] </td> </tr> <tr> <td style="padding-left: 12px;">[news]</td> </tr> </table> http://www.wpftutorial.net/Home.html Sat, 13 Mar 2010 21:01:00 +01002010-03-02 00:15:36 Watch Viedos about WPF moc@zuehlke.com (Christian Moser) <h1>Videos about WPF</h1> <h2>General</h2> <ul> <li><a href="http://channel9.msdn.com/pdc2008/PC46/">WPF Roadmap (PDC 2008)</a></li> <li><a href="http://microsoftpdc.com/Sessions/CL10?type=wmv">Windows Presentation Foundation 4 Plumbing and Internals</a></li> </ul> <h2>Multimedia</h2> <ul> <li><a href="http://windowsclient.net/learn/video.aspx?v=299630">How to use text-to-speech in WPF</a></li> </ul> http://www.wpftutorial.net/Videos.html Sat, 13 Mar 2010 21:01:00 +01002010-03-01 23:25:18 Third Party Controls moc@zuehlke.com (Christian Moser) <h1>WPF - Third Party Controls</h1> <table> <tr> <td style="vertical-align: top; width: 300px;"> <h2>Data Grids</h2> <ul> <li><a href="http://www.infragistics.com/dotnet/netadvantage/wpf/xamdatagrid.aspx#Overview">Infragistics Data Grid</a></li> <li><a href="http://xceed.com/Grid_WPF_New.html">Xceed Data Grid</a></li> <li><a href="http://www.componentone.com/SuperProducts/GridWPF/ ">Component One Data Grid</a></li> <li><a href="http://www.syncfusion.com/products/user-interface-edition/wpf/grid">Syncfusion Essential Grid</a></li> <li><a href="http://www.telerik.com/products/wpf/gridview.aspx">Telerik RadGridView for WPF</a></li> </ul> <h2>Charts</h2> <ul> <li><a href="http://www.infragistics.com/dotnet/netadvantage/wpf/xamchart.aspx#Overview ">Infragistics xamChart</a></li> <li><a href="http://sourceforge.net/projects/swordfishcharts">Swordfish Charts</a></li> <li><a href="http://www.componentone.com/SuperProducts/ChartWPF/ ">Component One Chart</a></li> <li><a href="http://www.visifire.com/">Visifire Chart for WPF and Silverlight</a></li> <li><a href="http://www.codeproject.com/KB/WPF/wpfgraph.aspx">WPF Graph on Code Project</a></li> <li><a href="http://www.codeproject.com/KB/WPF/WPF_3D_Bar_chart_control.aspx">Free 3D Chart</a></li> <li><a href="http://dynamicdatadisplay.codeplex.com/">D3 Dynamic Data Display</a></li> <li><a href="http://www.syncfusion.com/products/user-interface-edition/wpf/chart">Syncfusion Essential Chart</a></li> <li><a href="http://www.syncfusion.com/products/user-interface-edition/wpf/gauge">Syncfusion Gauge</a></li> <li><a href="http://www.telerik.com/products/wpf/gauge.aspx">Telerik RadGauge for WPF</a></li> <li><a href="http://www.telerik.com/products/wpf/chart.aspx">Telerik RadChart for WPF</a></li> </ul> <h2>Dialogs</h2> <ul> <li><a href="http://wpfdialogs.codeplex.com/">Pure WPF FileOpen, FileSave and FolderBrowser Dialogs</a></li> </ul> <h2>Dock</h2> <ul> <li><a <li><a href="http://www.infragistics.com/dotnet/netadvantage/wpf/xamdockmanager.aspx#Overview ">Infragistics Dock Manager</a></li> <li><a href="http://www.actiprosoftware.com/Products/DotNet/WPF/Docking/Default.aspx">Actipro Dock Panel</a></li> <li><a href="http://www.devcomponents.com/dotnetbar-wpf/">DevComponents Dock Panel</a></li> <li><a href="http://sourceforge.net/projects/wpfdockinglib/">WPF Docking Library (Open Source)</a></li> <li><a href="http://avalondock.codeplex.com">Avalon Dock (Open Source)</a></li> <li><a href="http://www.telerik.com/products/wpf/docking.aspx">Telerik RadDocking for WPF</a></li> </ul> <h2>Editors</h2> <ul> <li><a href="http://www.infragistics.com/dotnet/netadvantage/wpf/xameditors.aspx#Overview ">Infragistics xamEditors</a></li> <li><a href="http://xceed.com/Editors_WPF_Intro.html">Xceed Editors</a></li> <li><a href="http://www.devcomponents.com/dotnetbar-wpf/WPFNumericDoubleInput.aspx ">DevComponents Numeric Editor</a></li> <li><a href="http://www.telerik.com/products/wpf/numericupdown.aspx">Telerik RadNumericUpDown for WPF</a></li> <li><a href="http://www.syncfusion.com/products/user-interface-edition/wpf/edit">Syncfusion Essential Edit (with Syntax Highlighting)</a></li> <li><a href="http://www.syncfusion.com/products/user-interface-edition/wpf/diagram">Syncfusion Essential Diagram Editor</a></li> <li><a href="http://wpfcalendarcontrol.codeplex.com/">WPF Calendar Control</a></li> </ul> <h2>Effects</h2> <ul> <li><a href="http://www.codeplex.com/transitionals">Transitionals - Framework to transition between screens.</li> <li><a href="http://www.codeplex.com/fx">WPF Shader and Transition FX</a></li> <li><a href="http://www.codeplex.com/wpffx">Windows Presentation Foundation Pixel Shader Effects Library</a></li> <li><a href="http://www.codeplex.com/dotwaywpf">DotWay WPF - Color Picker, Panels and several Shader Effects</a></li> <li><a href="http://www.telerik.com/products/wpf/drag-drop.aspx">Telerik Drag&amp;Drop for WPF</a></li> </ul> <h2>GIS and Maps</h2> <ul> <li><a href="http://vewpf.codeplex.com/">Microsoft Virual Earth Control</a></li> <li><a href="http://wpfsharpmapcontrols.codeplex.com/">Sharp Map Control</a></li> </ul> <h2>Multimedia</h2> <ul> <li><a href="http://wpfcap.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=13380#ReleaseFiles">Webcam Control</a></li> <li><a href="http://www.codeplex.com/WPFMediaKit">WPF Media Kit - DVD Player, DirectShow, WebCam</li> </ul> </td> <td style="padding-left: 40px; vertical-align: top;"> <h2>Misc</h2> <ul> <li><a href="http://www.codeplex.com/wpf/Release/ProjectReleases.aspx?ReleaseId=15598">WPF Toolkit</a></li> <li><a href="http://www.infragistics.com/dotnet/netadvantage/wpf/xamTabControl.aspx#Overview ">Infragistics Tab Control</a></li> <li><a href="http://www.infragistics.com/dotnet/netadvantage/wpf/xamMonthCalendar.aspx#Overview">Infragistics MonthCalendar</a></li> <li><a href="http://www.actiprosoftware.com/Products/DotNet/WPF/BarCode/Default.aspx">Actipro BarCode</a></li> <li><a href="http://www.actiprosoftware.com/Products/DotNet/WPF/Wizard/Default.aspx">Actipro Wizard</a></li> <li><a href="http://www.actiprosoftware.com/Products/DotNet/WPF/PropertyGrid/Default.aspx">Actipro Property Grid</a></li> <li><a href="http://www.mindscape.co.nz/products/WpfPropertyGrid/default.aspx">Mindscape Property Grid</a></li> <li><a href="http://www.mindscape.co.nz/products/wpfflowdiagrams/">Mindscape Flow Diagrams</a></li> </ul> <h2>Outlook Bar</h2> <ul> <li><a href="http://www.infragistics.com/dotnet/netadvantage/wpf/xamOutlookBar.aspx#Overview ">Infragistics Outlook Bar</a></li> <li><a href="http://www.actiprosoftware.com/Products/DotNet/WPF/Navigation/Default.aspx">Actipro Outlook Bar</a></li> <li><a href="http://www.devcomponents.com/dotnetbar-wpf/NavigationPane.aspx">DevComponents Outlook Bar</a></li> <li><a href="http://www.codeproject.com/KB/WPF/WPFOutlookBar.aspx">Odyssey Outlook Bar</a></li> <li><a href="http://www.codeproject.com/KB/WPF/WPFExplorerBar.aspx">Odyssey Explorer Bar</a></li> <li><a href="http://www.telerik.com/products/wpf/outlookbar.aspx">Telerik RadOutlookBar for WPF</a></li> </ul> <h2>Panels</h2> <ul> <li><a href="http://www.infragistics.com/dotnet/netadvantage/wpf/xamcarouselpanel.aspx#Overview">Infragistics Carousel Panel</a></li> <li><a href="http://www.telerik.com/products/wpf/carousel.aspx">Telerik WPF Carousel Control</a></li> <li><a href="http://www.telerik.com/products/wpf/tileview.aspx">Telerik RadTileView for WPF</a></li> </ul> <h2>Reporting</h2> <ul> <li><a href="http://www.infragistics.com/dotnet/netadvantage/wpf/reporting.aspx#Overview ">Infragistics Reporting for WPF</a></li> <li><a href="http://www.componentone.com/SuperProducts/ReportsWPF/">Component One Reports</a></li> </ul> <h2>Toolbar</h2> <ul> <li><a href="http://fluent.codeplex.com">Fluent Ribbon Control Suite</a></li> <li><a href="http://www.infragistics.com/dotnet/netadvantage/wpf/xamRibbon.aspx#Overview">Infragistics Ribbon</a></li> <li><a href="http://www.actiprosoftware.com/Products/DotNet/WPF/Ribbon/Default.aspx">Actipro Ribbon</a></li> <li><a href="http://www.devcomponents.com/dotnetbar-wpf/wpfribbon/ ">DevComponents Ribbon</a></li> <li><a href="http://www.devexpress.com/Products/NET/Controls/WPF/Bar_Menu/">DevExpress ToolBar</a></li> <li><a href="http://www.codeproject.com/KB/tree/WPFBreadcrumbBar.aspx">Odyssey Breadcrumb Bar</a></li> <li><a href="http://www.codeproject.com/KB/WPF/OdysseyRibbonBar.aspx">Odyssey Ribbon</a></li> <li><a href="http://www.telerik.com/products/wpf/ribbonbar.aspx">Telerik WPF UI RibbonBar</a></li> </ul> <h2>Tree</h2> <ul> <li><a href="http://www.telerik.com/products/wpf/treeview.aspx">Telerik RadTree View for WPF</a></li> </ul> <h2>Schedule</h2> <ul> <li><a href="http://www.devcomponents.com/dotnetbar-wpf/WPFScheduleControl.aspx ">DevComponents Schedule Control</a></li> <li><a href="http://www.devcomponents.com/dotnetbar-wpf/WPFDateTimePicker.aspx ">DevComponents DateTime Picker</a></li> <li><a href="http://www.componentone.com/SuperProducts/ScheduleWPF/">Component One Schedule</a></li> <li><a href="http://timeline.codeplex.com/">Timeline Control</a></li> <li><a href="http://www.telerik.com/products/wpf/scheduler.aspx">Telerik RadScheduler for WPF</a></li> <li><a href="http://wpfschedule.codeplex.com/">Free WPF Schedule Control</a></li> </ul> <h2>3D</h2> <ul> <li><a href="http://xceed.com/3DViews_WPF_Intro.html">Xceed 3D Views</a></li> </ul> <h2>Web Browser</h2> <ul> <li><a href="http://wpfchromium.codeplex.com/SourceControl/changeset/view/28084#413984">Chromium Web Browser</a></li> </ul> </td> </tr> </table> http://www.wpftutorial.net/3rdPartyLibs.html Sat, 13 Mar 2010 21:01:00 +01002010-03-01 22:45:51 Calendar moc@zuehlke.com (Christian Moser) <h1>WPF Calendar Control</h1> <div style="text-align: right;"> <a href="uploads/Calendar.zip"><img src="images/download_sample.png"></a> </div> <h2>Introduction</h2> <p>Since WPF 4.0, Microsoft provides a full featured calendar control. It provides the following features: <ul> <li><a href="#displayDate">Set the displayed date</a></li> <li><a href="#selectionModes">Multiple selection modes</a></li> <li><a href="#blackout">Blackout dates</a></li> <li><a href="#modes">Calendar Modes</a></li> </ul> </p> <a name="displayDate"><h2>Set the displayed date</h2></a> <p>The calendar displays by default the current date. But you can specify any other date to be displayed by setting the <code>DisplayDate</code> property.</p> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;Calendar</span> <span style="color: #ff0000;">DisplayDate</span>=<span style="color: #0000ff;">&quot;01.01.2010&quot;</span> <span style="color: #800000;">/&gt;</span></span> </pre></div> <a name="selectionModes"><h2>Selection Modes</h2></a> <p>The calendar control provides multiple modes for selection. You can set the <code>SelectionMode</code> property to <code>SingleDate</code, <code>SingleRange</code>, <code>MultipleRanges</code> or <code>None</code>.</p> <img src="images/calendar1.png" style="padding-left: 100px;" /> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;Calendar</span> <span style="color: #ff0000;">SelectionMode</span>=<span style="color: #0000ff;">&quot;MultipleRange&quot;</span> <span style="color: #800000;">/&gt;</span></span> </pre></div> <a name="blackout"><h2>Blackout dates</h2></a> <p>The calendar control provides a feature to black out dates that are not valid for selection. You can define multiple ranges by setting the <code>BlackoutDates</code> property to one or multiple <code>CalendarDateRange</code>.</p> <img src="images/calendar2.png" style="padding-left: 100px;" /> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;Calendar</span> <span style="color: #ff0000;">SelectionMode</span>=<span style="color: #0000ff;">&quot;{Binding SelectedItem, ElementName=selectionmode}&quot;</span> <span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Calendar</span>.BlackoutDates<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;CalendarDateRange</span> <span style="color: #ff0000;">Start</span>=<span style="color: #0000ff;">&quot;01/01/2010&quot;</span> <span style="color: #ff0000;">End</span>=<span style="color: #0000ff;">&quot;01/06/2010&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;CalendarDateRange</span> <span style="color: #ff0000;">Start</span>=<span style="color: #0000ff;">&quot;05/01/2010&quot;</span> <span style="color: #ff0000;">End</span>=<span style="color: #0000ff;">&quot;05/03/2010&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/Calendar</span>.BlackoutDates<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/Calendar<span style="color: #800000;">&gt;</span></span></span> </pre></div> <a name="modes"><h2>Calendar Modes</h2></a> <p>The calendar supports three modes to display ranges of dates: <code>Year</code>, <code>Month</code> and <code>Decade</code>. You can control the mode by setting the <code>DisplayMode</code> property.</p> <img src="images/calendar3.png" style="padding-left: 100px;" /> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;Calendar</span> <span style="color: #ff0000;">DisplayMode</span>=<span style="color: #0000ff;">&quot;Year&quot;</span> <span style="color: #800000;">/&gt;</span></span> </pre></div> http://www.wpftutorial.net/Calendar.html Sat, 13 Mar 2010 21:01:00 +01002010-03-01 22:32:47 DataGrid moc@zuehlke.com (Christian Moser) <h1>WPF DataGrid Control</h1> <div style="text-align:right;"> <a href="uploads/DataGrid.zip"><img src="images/download_sample.png"></a> </div> <h2>Introduction</h2> <p>Since .NET 4.0, Microsoft is shipping a DataGrid control that provides all the basic functionality needed, like: <ul> <li><a href="#autoColumns">Auto generation of columns</a></li> <li><a href="#manualColumns">Manual definition of columns</a></li> <li><a href="#selection">Selection</a></li> <li><a href="#grouping">Grouping</a></li> <li><a href="#columnFeatures">Column sorting, reordering and resizing</a></li> <li><a href="#rowDetails">Row Details</a></li> <li><a href="#altbackgnd">Alternating BackgroundBrush</a></li> <li><a href="#frozenColumns">Frozen columns</a></li> <li><a href="#headers">Headers Visibility</a></li> </ul> <br/> <a name="autoColumns"><h2>Basic usage: Auto generate columns</h2></a> <p>To show a basic data grid , just drop a <code>DataGrid</code> control to your view and bind the <code>ItemsSource</code> to a collection of data objects and you're done. The DataGrid provides a feature called <code>AutoGenerateColumns</code> that automatically generates column according to the public properties of your data objects. It generates the following types of columns: <ul> <li>TextBox columns for string values</li> <li>CheckBox columns for boolean values</li> <li>ComboBox columns for enumerable values</li> <li>Hyperlink columns for Uri values</li> </ul> </p> <img src="images/datagrid1.png" style="padding-left: 30px;" /> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span> <span style="color: #ff0000;">ItemsSource</span>=<span style="color: #0000ff;">&quot;{Binding Customers}&quot;</span> <span style="color: #800000;">/&gt;</span></span> </pre></div><br/> <a name="manualColumns"><h2>Manually define columns</h2></a> <p>Alternatively you can define your columns manually by setting the <code>AutoGenerateColumns</code> property to <code>False</code>. In this case you have to define the columns in the <code>Columns</code> collection of the data grid. You have the following types of columns available: <ul> <li><code>DataGridCheckBoxColumn</code> for boolean values</li> <li><code>DataGridComboBoxColumn</code> for enumerable values</li> <li><code>DataGridHyperlinkColumn</code> for Uri values</li> <li><code>DataGridTemplateColumn</code> to show any types of data by defining your own cell template</li> <li><code>DataGridTextColumn</code> to show text values</li> </ul> </p> <img src="images/datagrid2.png" style="padding-left: 100px;" /> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span> <span style="color: #ff0000;">ItemsSource</span>=<span style="color: #0000ff;">&quot;{Binding Customers}&quot;</span> <span style="color: #ff0000;">AutoGenerateColumns</span>=<span style="color: #0000ff;">&quot;False&quot;</span> <span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span>.Columns<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGridTemplateColumn</span> <span style="color: #ff0000;">Header</span>=<span style="color: #0000ff;">&quot;Image&quot;</span> <span style="color: #ff0000;">Width</span>=<span style="color: #0000ff;">&quot;SizeToCells&quot;</span> <span style="color: #ff0000;">IsReadOnly</span>=<span style="color: #0000ff;">&quot;True&quot;</span><span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGridTemplateColumn</span>.CellTemplate<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;DataTemplate<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Image</span> <span style="color: #ff0000;">Source</span>=<span style="color: #0000ff;">&quot;{Binding Image}&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataTemplate<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataGridTemplateColumn</span>.CellTemplate<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataGridTemplateColumn<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataGrid</span>.Columns<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataGrid<span style="color: #800000;">&gt;</span></span></span> </pre></div><br/> <a name="selection"><h2>Selection</h2></a> <p>The data grid includes a variety of selection modes. They are configured by the <code>SelectionMode</code> and <code>SelectionUnit</code> property.</p> <ul> <li>The <b><code>SelectionMode</code></b> can be set to <code>Single</code> or <code>Extended</code> to define if one or multiple units can be selected simultaneously.</li> <li>The <b><code>SelectionUnit</code></b> defines the scope of one selection unit. It can be set to <code>Cell</code>, <code>CellAndRowHeader</code> and <code>FullRow</code>.</li> </ul> <img src="images/datagrid3.png" style="padding-left: 100px;" /> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span> <span style="color: #ff0000;">ItemsSource</span>=<span style="color: #0000ff;">&quot;{Binding Customers}&quot;</span> </span> <span style="color: #800000;"> <span style="color: #ff0000;">SelectionMode</span>=<span style="color: #0000ff;">&quot;Extended&quot;</span> <span style="color: #ff0000;">SelectionUnit</span>=<span style="color: #0000ff;">&quot;Cell&quot;</span> <span style="color: #800000;">/&gt;</span></span> </pre></div><br/> <a name="columnFeatures"><h2>Column sorting, reordering and resizing</h2></a> <p>The data grid provides features to sort, reorder and resize columns. They can be enabled or disabled by the following properties: <ul> <li><code>CanUserReorderColumns</code> enables or disables column re-ordering</li> <li><code>CanUserResizeColumns</code> enables or disables column resizing</li> <li><code>CanUserResizeRows</code> enables or disables row resizing</li> <li><code>CanUserSortColumns</code> enables or disables column sorting</li> </ul> </p> <img src="images/datagrid4.png" style="padding-left: 100px;" /> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span> <span style="color: #ff0000;">ItemsSource</span>=<span style="color: #0000ff;">&quot;{Binding Customers}&quot;</span> </span> <span style="color: #800000;"> <span style="color: #ff0000;">CanUserReorderColumns</span>=<span style="color: #0000ff;">&quot;True&quot;</span> <span style="color: #ff0000;">CanUserResizeColumns</span>=<span style="color: #0000ff;">&quot;True&quot;</span> </span> <span style="color: #800000;"> <span style="color: #ff0000;">CanUserResizeRows</span>=<span style="color: #0000ff;">&quot;False&quot;</span> <span style="color: #ff0000;">CanUserSortColumns</span>=<span style="color: #0000ff;">&quot;True&quot;</span><span style="color: #800000;">/&gt;</span></span> </pre></div><br/> <a name="grouping"><h2>Grouping</h2></a> <p>The data grid also supports grouping. To enable grouping you have to define a <code>CollectionView</code> that contains to least one <code>GroupDescription</code> that defines the criterias how to group.</p> <img src="images/datagrid6.png" style="padding-left: 100px;" /> <div class="codeblock"><pre class="csharp csharp" style="font-family: courier new,courier,monospace;"> Customers <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #0000ff; font-weight: bold;">new</span></a> ListCollectionView<span style="color: #000000;">&#40;</span>_customers<span style="color: #000000;">&#41;</span>; Customers.<span style="color: #0000FF;">GroupDescriptions</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #0000ff; font-weight: bold;">new</span></a> PropertyGroupDescription<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Gender&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; </pre></div> <p>Second thing you need to do is defining a template how the groups should look like. You can do this by setting the <code>GroupStyle</code> to something like the following snippet.</p> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span> <span style="color: #ff0000;">ItemsSource</span>=<span style="color: #0000ff;">&quot;{Binding GroupedCustomers}&quot;</span><span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span>.GroupStyle<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;GroupStyle<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;GroupStyle</span>.HeaderTemplate<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;DataTemplate<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;StackPanel<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;TextBlock</span> <span style="color: #ff0000;">Text</span>=<span style="color: #0000ff;">&quot;{Binding Path=Name}&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/StackPanel<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataTemplate<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/GroupStyle</span>.HeaderTemplate<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;GroupStyle</span>.ContainerStyle<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Style</span> <span style="color: #ff0000;">TargetType</span>=<span style="color: #0000ff;">&quot;{x:Type GroupItem}&quot;</span><span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Setter</span> <span style="color: #ff0000;">Property</span>=<span style="color: #0000ff;">&quot;Template&quot;</span><span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Setter</span>.Value<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;ControlTemplate</span> <span style="color: #ff0000;">TargetType</span>=<span style="color: #0000ff;">&quot;{x:Type GroupItem}&quot;</span><span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Expander<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Expander</span>.Header<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;StackPanel</span> <span style="color: #ff0000;">Orientation</span>=<span style="color: #0000ff;">&quot;Horizontal&quot;</span><span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;TextBlock</span> <span style="color: #ff0000;">Text</span>=<span style="color: #0000ff;">&quot;{Binding Path=Name}&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;TextBlock</span> <span style="color: #ff0000;">Text</span>=<span style="color: #0000ff;">&quot;{Binding Path=ItemCount}&quot;</span><span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;TextBlock</span> <span style="color: #ff0000;">Text</span>=<span style="color: #0000ff;">&quot;Items&quot;</span><span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/StackPanel<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/Expander</span>.Header<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;ItemsPresenter</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/Expander<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/ControlTemplate<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/Setter</span>.Value<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/Setter<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/Style<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/GroupStyle</span>.ContainerStyle<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/GroupStyle<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataGrid</span>.GroupStyle<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataGrid<span style="color: #800000;">&gt;</span></span></span> </pre></div> <br/> <a name="rowDetails"><h2>Row Details</h2></a> <p>The data grid provides a feature that shows a detail panel for a selected row. It can be enabled by setting a DataTemplate to the <code>RowDetailsTemplate</code> property. The data template gets the object that is bound to this row passed by the DataContext and can bind to it.</p> <img src="images/datagrid5.png" style="padding-left: 100px;" /> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span> <span style="color: #ff0000;">ItemsSource</span>=<span style="color: #0000ff;">&quot;{Binding Customers}&quot;</span><span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span>.Columns<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGridTextColumn</span> <span style="color: #ff0000;">Header</span>=<span style="color: #0000ff;">&quot;First Name&quot;</span> <span style="color: #ff0000;">Binding</span>=<span style="color: #0000ff;">&quot;{Binding FirstName}&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataGrid</span>.Columns<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span>.RowDetailsTemplate<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;DataTemplate<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Image</span> <span style="color: #ff0000;">Height</span>=<span style="color: #0000ff;">&quot;100&quot;</span> <span style="color: #ff0000;">Source</span>=<span style="color: #0000ff;">&quot;{Binding Image}&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataTemplate<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataGrid</span>.RowDetailsTemplate<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataGrid<span style="color: #800000;">&gt;</span></span></span> </pre></div> <h3>Row Details depending on the type of data</h3> <p>You can specify a <code>RowDetailsTemplateSelector</code> that selects a data template according to the type or data that this row contains. To do this, create a type that derives from <code>DataTemplateSelector</code> and override the <code>SelectTemplate</code> method. In the <code>items</code> argument you get the data and you can determine which data template to display. Return an instance of that data template as return value.</p> <img src="images/datagrid7.png" style="padding-left: 100px;" /> <div class="codeblock"><pre class="csharp csharp" style="font-family: courier new,courier,monospace;"> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #2b91af; font-weight: bold;">class</span> GenderTemplateSelector <span style="color: #008000;">:</span> DataTemplateSelector <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">public</span> DataTemplate MaleTemplate <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">public</span> DataTemplate FemaleTemplate <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> DataTemplate SelectTemplate<span style="color: #000000;">&#40;</span><span style="color: #2b91af; font-weight: bold;">object</span> item, DependencyObject container<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> var customer <span style="color: #008000;">=</span> item <span style="color: #0600FF; font-weight: bold;">as</span> Customer; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>customer <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">base</span>.<span style="color: #0000FF;">SelectTemplate</span><span style="color: #000000;">&#40;</span>item, container<span style="color: #000000;">&#41;</span>; <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> customer.<span style="color: #0000FF;">Gender</span> <span style="color: #008000;">==</span> Gender.<span style="color: #0000FF;">Male</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> MaleTemplate; <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">return</span> FemaleTemplate; <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> </pre></div><br/> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;l:GenderTemplateSelector</span> <span style="color: #ff0000;">x:Key</span>=<span style="color: #0000ff;">&quot;genderTemplateSelector&quot;</span><span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;l:GenderTemplateSelector</span>.MaleTemplate<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;DataTemplate<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Grid</span> <span style="color: #ff0000;">Background</span>=<span style="color: #0000ff;">&quot;LightBlue&quot;</span><span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Image</span> <span style="color: #ff0000;">Source</span>=<span style="color: #0000ff;">&quot;{Binding Image}&quot;</span> <span style="color: #ff0000;">Width</span>=<span style="color: #0000ff;">&quot;50&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/Grid<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataTemplate<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/l:GenderTemplateSelector</span>.MaleTemplate<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;l:GenderTemplateSelector</span>.FemaleTemplate<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;DataTemplate<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Grid</span> <span style="color: #ff0000;">Background</span>=<span style="color: #0000ff;">&quot;Salmon&quot;</span><span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Image</span> <span style="color: #ff0000;">Source</span>=<span style="color: #0000ff;">&quot;{Binding Image}&quot;</span> <span style="color: #ff0000;">Width</span>=<span style="color: #0000ff;">&quot;50&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/Grid<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/DataTemplate<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/l:GenderTemplateSelector</span>.FemaleTemplate<span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/l:GenderTemplateSelector<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span> <span style="color: #ff0000;">ItemsSource</span>=<span style="color: #0000ff;">&quot;{Binding Customers}&quot;</span> </span> <span style="color: #800000;"> <span style="color: #ff0000;">RowDetailsTemplateSelector</span>=<span style="color: #0000ff;">&quot;{StaticResource genderTemplateSelector}&quot;</span> <span style="color: #800000;">/&gt;</span></span> </pre></div> <a name="altbackgnd"><h2>Alternating BackgroundBrush</h2></a> <p>You can define a an <code>AlternatingRowBackground</code> that is applied every even row. You can additionally specify an <code>AlternationCount</code> if you only want to ink every every n-th data row.</p> <img src="images/datagrid8.png" style="padding-left: 100px;" /> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span> <span style="color: #ff0000;">ItemsSource</span>=<span style="color: #0000ff;">&quot;{Binding Customers}&quot;</span> </span> <span style="color: #800000;"> <span style="color: #ff0000;">AlternatingRowBackground</span>=<span style="color: #0000ff;">&quot;Gainsboro&quot;</span> <span style="color: #ff0000;">AlternationCount</span>=<span style="color: #0000ff;">&quot;2&quot;</span><span style="color: #800000;">/&gt;</span></span> </pre></div> <a name="frozenColumns"><h2>Frozen Columns</h2></a> <p>The data grid also supports the feature to freeze columns. That means they stay visible while you scoll horizontally through all columns. This is a useful feature to keep a referencing column like an ID or a name always visible to keep your orientation while scrolling.</p> <p>To freeze a numer of columns just set the <code>FrozenColumnCount</code> property to the number of columns you want to freeze.</p> <img src="images/datagrid9.png" style="padding-left: 100px;" /> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span> <span style="color: #ff0000;">ItemsSource</span>=<span style="color: #0000ff;">&quot;{Binding Customers}&quot;</span> <span style="color: #ff0000;">FrozenColumnCount</span>=<span style="color: #0000ff;">&quot;2&quot;</span> <span style="color: #800000;">/&gt;</span></span> </pre></div> <a name="headers"><h2>Headers visbility</h2></a> <p>You can control the visibility of row and column headers by setting the <code>HeadersVisibility</code> property to either <code>None</code>,<code>Row</code>,<code>Column</code> or <code>All</code></p> <img src="images/datagrid10.png" style="padding-left: 100px;" /> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;DataGrid</span> <span style="color: #ff0000;">ItemsSource</span>=<span style="color: #0000ff;">&quot;{Binding Customers}&quot;</span> <span style="color: #ff0000;">HeadersVisibility</span>=<span style="color: #0000ff;">&quot;None&quot;</span> <span style="color: #800000;">/&gt;</span></span> </pre></div> http://www.wpftutorial.net/DataGrid.html Sat, 13 Mar 2010 21:01:00 +01002010-03-01 21:34:07 Introduction to WPF moc@zuehlke.com (Christian Moser) <h1>Introduction to Windows Presentation Foundation</h1> <h2>Overview</h2> <p>The Windows Presentation Foundation is Microsofts next generation UI framework to create applications with a rich user experience. It is part of the .NET framework 3.0 and higher.</p> <p>WPF combines application UIs, 2D graphics, 3D graphics, documents and multimedia into one single framework. Its vector based rendering engine uses hardware acceleration of modern graphic cards. This makes the UI faster, scalable and resolution independent.</p> <p>The followinig illustration gives you an overview of the main new features of WPF</p> <img src="images/wpfMainFeatures.png" style="padding: 10px; padding-left: 120px;" /> <h2>Separation of Appearance and Behavior</h2> <p>WPF separates the appearance of an user interface from its behavior. The appearance is generally specified in the <a href="XAML.html">Extensible Application Markup Language</a> (XAML), the behavior is implemented in a managed programming language like C# or Visual Basic. The two parts are tied together by databinding, events and commands. The separation of appearance and behavior brings the following benefits: <ul> <li>Appearance and behaviour are loosely coupled</li> <li>Designers and developers can work on separate models.</li> <li>Graphical design tools can work on simple XML documents instead of parsing code.</li> </ul> </p> <h2>Rich composition</h2> <p>Controls in WPF are extremely composable. You can define almost any type of controls as content of another. Although these flexibility sounds horrible to designers, its a very powerful feature if you use it appropriate. Put an image into a button to create an image button, or put a list of videos into a combobox to choose a video file.</p> <img style="padding-left: 150px;" src="images/playsound_button.png" /> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;Button<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;StackPanel</span> <span style="color: #ff0000;">Orientation</span>=<span style="color: #0000ff;">&quot;Horizontal&quot;</span><span style="color: #800000;">&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;Image</span> <span style="color: #ff0000;">Source</span>=<span style="color: #0000ff;">&quot;speaker.png&quot;</span> <span style="color: #ff0000;">Stretch</span>=<span style="color: #0000ff;">&quot;Uniform&quot;</span><span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;TextBlock</span> <span style="color: #ff0000;">Text</span>=<span style="color: #0000ff;">&quot;Play Sound&quot;</span> <span style="color: #800000;">/&gt;</span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/StackPanel<span style="color: #800000;">&gt;</span></span></span> <span style="color: #800000;"><span style="color: #800000;">&lt;/Button<span style="color: #800000;">&gt;</span></span></span> </pre></div> <h2>Highly customizable</h2> <p>Because of the strict separation of appearance and behavior you can easily change the look of a control. The concept of <a href="Styles.html">styles</a> let you skin controls almost like CSS in HTML. <a href="Templates.html">Templates</a> let you replace the entire appearance of a control.</p> <p>The following example shows an default WPF button and a customized button.</p> <img style="padding-left: 100px;" src="images/introduction_buttons.png" /> <h2>Resolution independence</h2> <p>All measures in WPF are logical units - not pixels. A logical unit is a 1/96 of an inch. If you increase the resolution of your screen, the user interface stays the same size - if just gets crispier. Since WPF builds on a vector based rendering engine it's incredibly easy to build scaleable user interfaces.</p> <img style="padding-left: 120px;" src="images/wpf_scaling.png" /> http://www.wpftutorial.net/WPFIntroduction.html Sat, 13 Mar 2010 21:01:00 +01002010-03-01 19:53:34 Read Books about WPF moc@zuehlke.com (Christian Moser) <h1>Books about WPF</h1> <h2>Brand New!</h2> <table width="700"> <tr style="height: 200px;"> <td><img src="images/book_wpfcontroldev.png" style="width: 150px;"></td> <td style="vertical-align: top;"> <h3>WPF Control Development Unleashed</h3> <p>In this book, two leading Windows Presentation Foundation experts give developers everything they need to build next-generation WPF applications--software that is more robust, usable, and compelling. Drawing on their close ties with Microsoft's WPF development team, Pavan Podila and Kevin Hoffman give you a clear, robust, and practical understanding of WPF, its underpinnings, its overall architecture, and its design philosophy.</p> <p><table> <tr> <td style="width: 100px;"><b>Autor:</b></td> <td>Pavan Podila, Kevin Hoffman</td> </tr> <tr> <td style="width: 100px;"><b>ISBN:</b></td> <td>978-0672330339</td> </tr> <tr> <td style="width: 100px;"><b>Published:</b></td> <td>September 2009</td> </tr> <tr> <td></td> <td><a href="http://www.amazon.de/gp/product/0672330334/ref=sib_rdr_dp" target="_blank">Find it at Amazon</td> </tr> </table> </p> </td> </tr> </table> <br/><br/> <hr /> <table width="700"> <tr style="height: 200px;"> <td><img src="images/book_wpfunleashed.jpg" style="width: 150px;"></td> <td style="vertical-align: top;"> <h3>Windows Presentation Foundation - Unleashed (My favorite!)</h3> <p>In my opinion one of the best book about WPF. It covers all important themes including 3D programming. All code samples have syntax highlighting. Digging deeper sections with additional informations for advanced programmers.</p> <p><table> <tr> <td style="width: 100px;"><b>Autor:</b></td> <td>Adam Nathan</td> </tr> <tr> <td style="width: 100px;"><b>ISBN:</b></td> <td>978-0672328916</td> </tr> <tr> <td style="width: 100px;"><b>Published:</b></td> <td>January 2007</td> </tr> <tr> <td></td> <td><a href="http://www.amazon.de/Windows-Presentation-Foundation-Unleashed-Nathan/dp/0672328917/ref=pd_sim_eb_1" target="_blank">Find it at Amazon</td> </tr> </table> </p> </td> </tr> <tr style="height: 200px;"> <td><img src="images/book_appcodemarkup.jpg" style="width: 130px;"></td> <td style="vertical-align: top;"> <h3>Application = Code + Markup</h3> <p>"Get the definitive guide to the Windows Presentation Foundation (WPF), the new client programming interface for the Microsoft .NET Framework 3.0 and Windows Vista. Award-winning author Charles Petzold teaches you how to combine C# code and the Extensible Application Markup Language (XAML) to develop applications for the WPF.". I cannot unterstand how anyone can write a book about a UI technology without a single illustration. If you prefer gray text to colorful images, it might be the book for you. </p> <p><table> <tr> <td style="width: 100px;"><b>Autor:</b></td> <td>Charles Petzold</td> </tr> <tr> <td style="width: 100px;"><b>ISBN:</b></td> <td>978-0735619579</td> </tr> <tr> <td style="width: 100px;"><b>Published:</b></td> <td>August 2006</td> </tr> </table> </p> </td> </tr> <tr style="height: 200px;"> <td><img src="images/book_essentialwpf.jpg" style="width: 130px;"></td> <td style="vertical-align: top;"> <h3>Essential Windows Presentation Foundation</h3> <p>Chris Anderson was one of the chief architects of the next-generation GUI stack, the Windows Presentation Framework (WPF), which is the subject of this book. Chris's insights shine a light from the internals of WPF to those standing at the entrance, guiding you through the concepts that form the foundation of his creation.</p> <p><table> <tr> <td style="width: 100px;"><b>Autor:</b></td> <td>Chris Anderson</td> </tr> <tr> <td style="width: 100px;"><b>ISBN:</b></td> <td>978-0321374479</td> </tr> <tr> <td style="width: 100px;"><b>Published:</b></td> <td>April 2007</td> </tr> </table> </p> </td> </tr> <tr style="height: 200px;"> <td><img src="images/book_foundations.jpg" style="width: 130px;"></td> <td style="vertical-align: top;"> <h3>Foundations of WPF: An Introduction to Windows Presentation Foundation </h3> <p>Foundations of WPF: An Introduction to Windows Presentation Foundation teaches you everything you need to get started with the technology, and is broken into three parts. The first introduces and contextualizes the WPF technology; the second part dives deeper into the facets of the technology that are of immediate and valuable use in developing applications; the last part offers you the real-world perspective you need to be productive in the community and customer base.</p> <p><table> <tr> <td style="width: 100px;"><b>Autor:</b></td> <td>Laurence Moroney</td> </tr> <tr> <td style="width: 100px;"><b>ISBN:</b></td> <td>978-1590597606</td> </tr> <tr> <td style="width: 100px;"><b>Published:</b></td> <td>November 2006</td> </tr> </table> </p> </td> </tr> <tr style="height: 200px;"> <td><img src="images/book_prowpf.jpg" style="width: 130px;"></td> <td style="vertical-align: top;"> <h3>Pro WPF in C# 2008</h3> <p>This book explains how WPF works from the ground up. It follows on from the author s previous and highly successful books, covering Windows Forms (WPF's predecessor technology) and earlier versions of WPF. It is a one-stop shop in Apress proven Pro style that leaves readers with a deep understanding of the technology and able to take the concepts away and apply them for themselves.</p> <p><table> <tr> <td style="width: 100px;"><b>Autor:</b></td> <td>Matthew McDonald</td> </tr> <tr> <td style="width: 100px;"><b>ISBN:</b></td> <td>978-1590599556</td> </tr> <tr> <td style="width: 100px;"><b>Published:</b></td> <td>Februar 2008</td> </tr> </table> </p> </td> </tr> <tr style="height: 200px;"> <td><img src="images/book_programming_wpf.jpg" style="width: 130px;"></td> <td style="vertical-align: top;"> <h3>Foundations of WPF: An Introduction to Windows Presentation Foundation </h3> <p>If you want to build applications that take full advantage of Windows Vista's new user interface capabilities, you need to learn Microsoft's Windows Presentation Foundation (WPF). This new edition, fully updated for the official release of .NET 3.0, is designed to get you up to speed on this technology quickly.</p> <p><table> <tr> <td style="width: 100px;"><b>Autor:</b></td> <td>Chris Sells and Ian Griffiths</td> </tr> <tr> <td style="width: 100px;"><b>ISBN:</b></td> <td>978-0596510374</td> </tr> <tr> <td style="width: 100px;"><b>Published:</b></td> <td>September 2007</td> </tr> </table> </p> </td> </tr> </table> http://www.wpftutorial.net/WPFBools.html Sat, 13 Mar 2010 21:01:00 +01002010-03-01 10:26:48 Evaluate a localization mechanism moc@zuehlke.com (Christian Moser) <h1>How to evaluate a localization mechanism</h1> <h2>Criterias for evaluation</h2> <p>To choose an appropriate localization mechanism you have to find one that meets the requirements and your companys established translation process.</p> <p>Criterias to compare the localization mechanisms among each others: <ul> <li>Dynamic language switching</li> <li>Usage in XAML and Code</li> <li>Types of applicable resources</li> <li>Ease and flexibility of use</li> <li>Translation performance</li> </ul> </p> <h2>Different WPF translation mechanisms compared</h2> <ul> <li><a href="LocalizeMarkupExtension.html">Localization using a MarkupExtension</a></li> <li><a href="LocalizationUsingSateliteAssemblies.html">Localization using Satellite Assemblies</a></li> </ul> http://www.wpftutorial.net/EvaluateLocalizationMechanism.html Sat, 13 Mar 2010 21:01:00 +01002010-02-25 08:31:07 Localization using Satelite Assemblies moc@zuehlke.com (Christian Moser) <h1>Localization using Satelite Assemblies</h1> <a href="http://msdn.microsoft.com/en-us/library/ms746621.aspx">MSDN Documentation about Localization</a> http://www.wpftutorial.net/LocalizationUsingSateliteAssemblies.html Sat, 13 Mar 2010 21:01:00 +01002010-02-25 07:57:28 Localization using a MarkupExtension moc@zuehlke.com (Christian Moser) <h1>Localization of a WPF application using a custom MarkupExtension</h1> <div style="text-align: right;"> <b><a href="uploads/TranslationByMarkupExtension.zip"><img src="images/download_sample.png"></a></b> </div> <img src="images/markupextension.png" style="padding-left: 50px;" /> <h2>The Idea</h2> <p>A simple and effective way to localize application resources is to write a custom <code>MarkupExtension</code> that provides a localized value. The extension takes a parameter in the constructor that is the unique resource key. When the DepdendencyProperty asks for the value, the markup extension looks up the value from a generic resource provider. This gives you the flexibility to reuse the resource management and translation process that is already established within your company.</p> <p>Using a custom markup extension has some advantages</a> <ul> <li>Lightweight and flexible solution</li> <li>Dynamic language switch at runtime</li> <li>Works with any kind of resource providers.</li> </ul> <h2>How to use it</h2> <p>The usage of the markup extension is very simple. Just replace the string you want to localize by <code>{l:Translate resourceKey}</code>.</p> <div class="codeblock"><pre class="xaml xaml" style="font-family: courier new,courier,monospace;"> <span style="color: #800000;"><span style="color: #800000;">&lt;TextBlock</span> <span style="color: #ff0000;">Text</span>=<span style="color: #0000ff;">&quot;{l:Translate CustomerForm.FirstName}&quot;</span> <span style="color: #800000;">/&gt;</span></span> </pre></div> <h2>Implementation details of the translation infrastructure</h2> <p>The translation infrastructure consists of the folling parts <ul> <li><b>Translation manager</b><br/> The translation manager is a static class that manages the current language and notifies all markup extensions, to update their values when the language changes. It also provides access to translated resources. The resources itself are provided by a generic translation provider.<br/><br/></li> <li><b>Translate markup extension</b><br/> The tanslate markup extension knows the resource key and provides the translated value. It listens to the LanguageChanged event of the translation manager and updates its value. This event handler is implemented by the weak event pattern to prevent memory leaks.<br/><br/></li> <li><b>Translation provider</b><br/> The translation provider is a class that provides the translated resources. It has to implement the <code>ITranslationProvider</code> and can access any kind of resources you like. For e.g. ResX, XML or text files.</li> </ul> </p> <div class="codeblock"><pre class="csharp csharp" style="font-family: courier new,courier,monospace;"> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #2b91af; font-weight: bold;">class</span> TranslateExtension <span style="color: #008000;">:</span> MarkupExtension <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #2b91af; font-weight: bold;">string</span> _key; <span style="color: #0600FF; font-weight: bold;">public</span> TranslateExtension<span style="color: #000000;">&#40;</span><span style="color: #2b91af; font-weight: bold;">string</span> key<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> _key <span style="color: #008000;">=</span> key; <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#91;</span>ConstructorArgument<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;key&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #2b91af; font-weight: bold;">string</span> Key <span style="color: #000000;">&#123;</span> get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> _key; <span style="color: #000000;">&#125;</span> set <span style="color: #000000;">&#123;</span> _key <span style="color: #008000;">=</span> value;<span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #2b91af; font-weight: bold;">object</span> ProvideValue<span style="color: #000000;">&#40;</span>IServiceProvider serviceProvider<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> var binding <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #0000ff; font-weight: bold;">new</span></a> Binding<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Value&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> Source <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #0000ff; font-weight: bold;">new</span></a> TranslationData<span style="color: #000000;">&#40;</span>_key<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>; <span style="color: #0600FF; font-weight: bold;">return</span> binding.<span style="color: #0000FF;">ProvideValue</span><span style="color: #000000;">&#40;</span>serviceProvider<span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> </pre></div> <div class="codeblock"><pre class="csharp csharp" style="font-family: courier new,courier,monospace;"> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #2b91af; font-weight: bold;">class</span> TranslationData <span style="color: #008000;">:</span> IWeakEventListener, INotifyPropertyChanged <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #2b91af; font-weight: bold;">string</span> _key; <span style="color: #0600FF; font-weight: bold;">public</span> TranslationData<span style="color: #000000;">&#40;</span> <span style="color: #2b91af; font-weight: bold;">string</span> key<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> _key <span style="color: #008000;">=</span> key; LanguageChangedEventManager.<span style="color: #0000FF;">AddListener</span><span style="color: #000000;">&#40;</span> TranslationManager.<span style="color: #0000FF;">Instance</span>, <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span> ~TranslationData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> LanguageChangedEventManager.<span style="color: #0000FF;">RemoveListener</span><span style="color: #000000;">&#40;</span> TranslationManager.<span style="color: #0000FF;">Instance</span>, <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #2b91af; font-weight: bold;">object</span> Value <span style="color: #000000;">&#123;</span> get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> TranslationManager.<span style="color: #0000FF;">Instance</span>.<span style="color: #0000FF;">Translate</span><span style="color: #000000;">&#40;</span>_key<span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #2b91af; font-weight: bold;">bool</span> ReceiveWeakEvent<span style="color: #000000;">&#40;</span>Type managerType, <span style="color: #2b91af; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>managerType <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #0000ff; font-weight: bold;">typeof</span></a><span style="color: #000000;">&#40;</span>LanguageChangedEventManager<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> OnLanguageChanged<span style="color: #000000;">&#40;</span>sender, e<span style="color: #000000;">&#41;</span>; <span style="color: #0600FF; font-weight: bold;">return</span> true; <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">return</span> false; <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">void</span> OnLanguageChanged<span style="color: #000000;">&#40;</span><span style="color: #2b91af; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> PropertyChanged <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> PropertyChanged<span style="color: #000000;">&#40;</span> <span style="color: #0600FF; font-weight: bold;">this</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #0000ff; font-weight: bold;">new</span></a> PropertyChangedEventArgs<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Value&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">event</span> PropertyChangedEventHandler PropertyChanged; <span style="color: #000000;">&#125;</span> </pre></div> <div class="codeblock"><pre class="csharp csharp" style="font-family: courier new,courier,monospace;"> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #2b91af; font-weight: bold;">class</span> TranslationManager <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> TranslationManager _translationManager; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">event</span> EventHandler LanguageChanged; <span style="color: #0600FF; font-weight: bold;">public</span> CultureInfo CurrentLanguage <span style="color: #000000;">&#123;</span> get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> Thread.<span style="color: #0000FF;">CurrentThread</span>.<span style="color: #0000FF;">CurrentUICulture</span>; <span style="color: #000000;">&#125;</span> set <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> value <span style="color: #008000;">!=</span> Thread.<span style="color: #0000FF;">CurrentThread</span>.<span style="color: #0000FF;">CurrentUICulture</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> Thread.<span style="color: #0000FF;">CurrentThread</span>.<span style="color: #0000FF;">CurrentUICulture</span> <span style="color: #008000;">=</span> value; OnLanguageChanged<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">public</span> IEnumerable<span style="color: #008000;">&lt;</span>CultureInfo<span style="color: #008000;">&gt;</span> Languages <span style="color: #000000;">&#123;</span> get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> TranslationProvider <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> TranslationProvider.<span style="color: #0000FF;">Languages</span>; <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">return</span> Enumerable.<span style="color: #0000FF;">Empty</span><span style="color: #008000;">&lt;</span>CultureInfo<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> TranslationManager Instance <span style="color: #000000;">&#123;</span> get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_translationManager <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> _translationManager <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #0000ff; font-weight: bold;">new</span></a> TranslationManager<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #0600FF; font-weight: bold;">return</span> _translationManager; <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">public</span> ITranslationProvider TranslationProvider <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">void</span> OnLanguageChanged<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>LanguageChanged <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> LanguageChanged<span style="color: #000000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, EventArgs.<span style="color: #0000FF;">Empty</span><span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #2b91af; font-weight: bold;">object</span> Translate<span style="color: #000000;">&#40;</span><span style="color: #2b91af; font-weight: bold;">string</span> key<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> TranslationProvider<span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #2b91af; font-weight: bold;">object</span> translatedValue <span style="color: #008000;">=</span>TranslationProvider.<span style="color: #0000FF;">Translate</span><span style="color: #000000;">&#40;</span>key<span style="color: #000000;">&#41;</span>; <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> translatedValue <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> translatedValue; <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #2b91af; font-weight: bold;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;!{0}!&quot;</span>, key<span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> </pre></div> http://www.wpftutorial.net/LocalizeMarkupExtension.html Sat, 13 Mar 2010 21:01:00 +01002010-02-24 01:21:25 Localization moc@zuehlke.com (Christian Moser) <h1>Localization in WPF</h1> [sublist] http://www.wpftutorial.net/Localisation.html Sat, 13 Mar 2010 21:01:00 +01002010-02-23 00:17:46 Weak Event Pattern moc@zuehlke.com (Christian Moser) <h1>Weak Event Pattern</h1> <h2>Introduction</h2> <p>Events can easily cause memory leaks, if the handler is not de-registrated, because the event source helds a reference to the object and so the garbage collector will not destroy the object. WPF introduces the "weak event" design pattern, that addresses this issue by providing a dedicated event manager that does the trick.</p> http://www.wpftutorial.net/WeakEventPattern.html Sat, 13 Mar 2010 21:01:00 +01002010-02-22 23:25:46