Volunteer .NET Evangelist

A well oiled machine can’t run efficiently, if you grease it with water.
posts - 44, comments - 88, trackbacks - 2, articles - 0
  首页  :: 联系 :: 订阅 订阅  :: 管理

Two Xaml Tricks

Posted on 2006-10-03 15:18  Sheva  阅读(1707)  评论(2编辑  收藏
1. Declare array object in xaml:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

<ListBox Width="200" Height="200" BorderBrush="Navy" BorderThickness="1">
<x:Array Type="{x:Type sys:String}">
<sys:String>Paviel Dedved</sys:String>
<sys:String>Andriy Shevchenko</sys:String>
<sys:String>Paolo Maldini</sys:String>
<sys:String>Robert Baggio</sys:String>
<sys:String>Alessandro Del Piero</sys:String>

Declare inline code in Xaml:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      private void ButtonClickEventHandler(Object sender, RoutedEventArgs e)
          MessageBox.Show("Hello Xaml!");
<Button Width="200" Height="60" Content="Click Me" Click="ButtonClickEventHandler"/>

    Note that, when specifying inline code in xaml, you also need to specify the x:Class and the Xaml should be compiled before getting execution, which means that XamlReader.Load() method cannot intepret the xaml which contains inline code.