前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Silverlight 4 中数据绑定发生的变化

Silverlight 4 中数据绑定发生的变化

作者头像
用户1172164
发布2018-01-16 11:50:46
1.1K0
发布2018-01-16 11:50:46
举报
文章被收录于专栏:我和未来有约会

DependencyObject Binding

在Silverlight之前的版本中,其支持的元素绑定只是允许绑定继承自FrameworkElement类下元素,但是比如一些形变比如Transformations就不能绑定了。现在数据绑定也可以绑定继承自DependencyObject下的任何元素。

==============================

代码语言:javascript
复制
    <Grid x:Name="LayoutRoot"
      Background="White">
        <StackPanel Width="400" Margin="0,22,0,0">
            <StackPanel.RenderTransform>
                <CompositeTransform 
        ScaleX="{Binding Value,ElementName=stretcher}"
        ScaleY="{Binding Value,ElementName=stretcher}" />
            </StackPanel.RenderTransform>
         <Button Content="Button"/>
         <Button Content="Button"/>
         <Button Content="Button"/>
         <Button Content="Button"/>
         <Button Content="Button"/>
        </StackPanel>
        <Slider Minimum=".5"
          Maximum="4"
          x:Name="stretcher"
          Value="1" VerticalAlignment="Top" />
    </Grid>

=================================

String Formatting 新版的Silverlight4中新增加了格式化字符串的能力。在这之前如果要做一个数据格式化不得不使用一个Converter来格式化字符串。现在可以使用扩展标记StringFormat来做一些比如日期、货币等的格式化。

在VS2010中也提供了可视化的支持。

=================================

代码语言:javascript
复制
    <Grid x:Name="LayoutRoot" Background="White">
        <TextBox Text="{Binding ReleaseDate, StringFormat='yyyy年MM月dd日', 
                        Mode=TwoWay}" 
                 Margin="0,30,0,0" 
                 Height="26" 
                 VerticalAlignment="Top" d:LayoutOverrides="Height" />
        <TextBlock Text="{Binding Price, StringFormat='c'}" 
                   Margin="0,0,0,0" 
                   Height="26" VerticalAlignment="Top" />
    </Grid>

=================================

Null and Fallback Values 在某些特殊的情况下,数据有可能加载失败。数据绑定中有新增加了两个宽展标记TargetNullValue、FallbackValue,TargetNullValue这个标记表示了当绑定值是null的时候显示的值。FallbackValue则是在数据未绑定时显示的值。 =================================

代码语言:javascript
复制
    <Grid x:Name="LayoutRoot" Background="White">
        <TextBlock Text="{Binding Developer,
            TargetNullValue='(暂无)'}" 
                   Height="26" Margin="0,100,0,0" 
                   VerticalAlignment="Top" d:LayoutOverrides="Height" />
        <TextBlock Text="{Binding Publisher, 
            FallbackValue='(暂无)'}" Height="26" 
                   VerticalAlignment="Top" Margin="0,33,0,0" />
    </Grid>

=================================

CollectionViewSource Changes 对于在GataGrid中做分组管理,现在的CollectionViewSource支持数据到GroupDescriptions的绑定,这样可以更加轻松的在XAML做分组。

=================================

代码语言:javascript
复制
    <UserControl.Resources>
        <CollectionViewSource x:Name="dataSource" 
      Source="{Binding}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Gender" />
                <PropertyGroupDescription PropertyName="AgeGroup" />
            </CollectionViewSource.GroupDescriptions>
            <CollectionViewSource.SortDescriptions>
                <compMod:SortDescription PropertyName="AgeGroup" Direction="Ascending"/>                
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <sdk:DataGrid ItemsSource="{Binding Source={StaticResource dataSource}}" />
    </Grid>

=================================

=================================

代码语言:javascript
复制
        public List<Person> GetPeople()
        {
            List<Person> peeps = new List<Person>();
            peeps.Add(new Person() { FirstName = "Wang", LastName = "Zhe", Gender = "M", AgeGroup = "Adult" });
            peeps.Add(new Person() { FirstName = "nasa", LastName = "wang", Gender = "M", AgeGroup = "Adult" });
            peeps.Add(new Person() { FirstName = "summer", LastName = "liang", Gender = "F", AgeGroup = "Kid" });
            peeps.Add(new Person() { FirstName = "liang", LastName = "jing", Gender = "F", AgeGroup = "Kid" });
            return peeps;
        }

=================================

Error Propogation Silverlight的数据验证机制,在这里得到了很多的扩充,提供了IDataErrorInfoINotifyDataErrorInfo从而能得到更多的信息。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2010-04-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档