Microsoft . 技术之路...

—— 专注于微软技术, 分享是快乐的源泉......
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Wpf下Xaml语句新旧语法对照

Posted on 2006-09-07 11:20  赣江源  阅读(459)  评论(0编辑  收藏  举报

1) XML 命名空间地址改变:
 

OLD

http://schemas.microsoft.com/winfx/avalon/2005

NEW

http://schemas.microsoft.com/winfx/2006/xaml/presentation

 

OLD

http://schemas.microsoft.com/winfx/xaml/2005

NEW

http://schemas.microsoft.com/winfx/2006/xaml

 

 

2) mapping 语法的改变:
 

OLD

<?Mapping XmlNamespace="local" ClrNamespace="MyCompany.MyProduct" ?>
<… xmlns:my="local" >

NEW

<… xmlns:my="clr-namespace:MyCompany.MyProduct" >

 

OLD

<?Mapping XmlNamespace="local" ClrNamespace="MyCompany.MyProduct" Assembly="someDLL" ?>
<… xmlns:my="local" >

NEW

<… xmlns:my="clr-namespace:MyCompany.MyProduct;assembly=someDLL" >


更多相关描述: http://msdn2.microsoft.com/en-us/library/system.reflection.assemblyname.aspx


3) Grids指定行列.

OLD

<Grid>
 <ColumnDefinition />
</Grid>.

NEW
<Grid>
  <ColumnDefinitions>
    <ColumnDefinition/>
  </ColumnDefinitions>
</Grid>


4) 数据邦定时必须明确声明邦定对象的属性.

OLD
<TextBox.Text>{Binding}</TextBox.Text>

NEW
Text = “{Binding}”

5) System.Windows.Serialization  现在变成 System.Windows.Markup

6) 用户自定义控件的改变.

OLD

<UserControl>
 <UserControl.FixedTemplate>
    <Grid>
    </Grid>
 </UserControl.FixedTemplate>
</UserControl>

 

NEW
<UserControl>
  <Grid>
  </Grid>
</UserControl>


7) 多媒体的属性与方法. 

MediaElement myME;

OLD

myME.Player.Play();

NEW

myME.Play(); // new


8) 多媒体的行为变化

In the Jan CTP, the following XAML would play the video file until the file ended, or until the MediaElement was GCd. 

<MediaElement Source=”a.wmv”>

A MediaElement now stops when it is Unloaded by default.

If MediaElement is incorporated into a visual that does not propagate OnLoaded and Unloaded events (such as VisualBrush), it won’t play automatically on Load. There are a number of work-around for this:

If you want to preserve the old behavior of MediaElement of starting to play at parse time rather than OnLoaded - <MediaElement Source=”foo” UnloadedBehavior=”Play”/>

If you want to use a Storyboard - <MediaElement UnloadedBehavior=”Manual”/>

If you want to use code-behind - <MediaElement UnloadedBehavior=”Manual”/>
 

9) 在XAML 文件中插入XML Data, XML 源必须包含在一个 x:XData 标签内:
 

OLD

<XmlDataProvider x:Key="aXmlDP">

    <Root xmlns="">

        <Number type="int">333</Number>

    </Root>

</XmlDataProvider>


NEW

<XmlDataProvider x:Key="aXmlDP">

    <x:XData>

        <Root xmlns="">

            <Number type="int">333</Number>

        </Root>

    </x:XData>

</XmlDataProvider>

 11) SinglePageViewer 改变成 FlowDocumentPageViewer

12) relative源绑定的语法改变:

OLD

{Binding Path=foo, RelativeSource=/TemplatedParent}

NEW

{Binding Path=foo, RelativeSource='{RelativeSource TemplatedParent}'