Volunteer .NET Evangelist

A well oiled machine can’t run efficiently, if you grease it with water.
   :: 首页 ::  :: 联系 :: 订阅 订阅 :: 管理

Two Xaml Tricks

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

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:sys
="clr-namespace:System;assembly=mscorlib">

    
<Grid>
        
<ListBox Width="200" Height="200" BorderBrush="Navy" BorderThickness="1">
            
<ListBox.ItemsSource>
                
<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>
                
</x:Array>
            
</ListBox.ItemsSource>
        
</ListBox>
    
</Grid>
</Page>

2.
Declare inline code in Xaml:

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

    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.

Feedback

#1楼    回复  引用  查看    

2006-10-03 21:18 by phinecos(洞庭散人)      
就两段代码?楼主还是应该写详细点呀。。。

#2楼    回复  引用  查看    

2007-06-27 22:55 by 王计平      
这么简单的代码还用解释,有些编程经验的话一看就懂了

标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2006-10-03 20:46 编辑过


相关链接: