Hidden features of WPF and XAML?

Here is a large number of hidden features discussed for variety of languages. Now I am curious about some hidden features of XAML and WPF?

One I have found is the header click event of a ListView

<ListView x:Name='lv' 
      Height="150" 
      GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler">

The GridViewColumnHeader.Click property is not listed.

Some of relevant features so far:

  • Multibinding combined with StringFormat

  • TargetNullValue to bindings

  • TextTrimming property

  • Markup extensions

  • Adding Aero effect to Window

  • Advanced "caption" properties

  • XAML Converters

  • See also:

  • Hidden features of C#
  • Hidden features of Python
  • Hidden features of ASP.NET
  • Hidden features of Perl
  • Hidden features of Java
  • Hidden features of VB.NET
  • Hidden features of PHP
  • Hidden features of Ruby
  • Hidden features of C
  • And So On........

  • 多重绑定(与StringFormat组合):

    <TextBlock>
      <TextBlock.Text>
        <MultiBinding StringFormat="{}{0}, {1}">
          <Binding Path="LastName" />
          <Binding Path="FirstName" />
        </MultiBinding>
      </TextBlock.Text>
    </TextBlock>
    

    There is also PresentationTraceSources.TraceLevel trick to debug what is going on with bindings in any particular scenario. All you have to do is to reference System.Diagnostics namespace in WindowsBase assembly

    xmlns:sd="clr-namespace:System.Diagnostics;assembly=WindowsBase"
    

    and then add following to the binding expression:

    <TextBlock Text="{Binding Message, sd:PresentationTraceSources.TraceLevel=High}"  />
    

    Log will be like this:

    System.Windows.Data Warning: 52 : Created BindingExpression (hash=5923895) for Binding (hash=7588182)
    System.Windows.Data Warning: 54 :   Path: 'Message'
    System.Windows.Data Warning: 56 : BindingExpression (hash=5923895): Default mode resolved to OneWay
    System.Windows.Data Warning: 57 : BindingExpression (hash=5923895): Default update trigger resolved to PropertyChanged
    System.Windows.Data Warning: 58 : BindingExpression (hash=5923895): Attach to System.Windows.Controls.TextBlock.Text (hash=65248697)
    System.Windows.Data Warning: 63 : BindingExpression (hash=5923895): Resolving source 
    

    3.5sp1 introduced TargetNullValue to bindings. This will set the bound property to Null if the value is entered and if your property is Null it will display this value.

    <TextBox Text="{Binding Total, TargetNullValue=$0.00}" />
    
    链接地址: http://www.djcxy.com/p/42810.html

    上一篇: Bash的隐藏功能

    下一篇: WPF和XAML的隐藏功能?