自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

詳解Silverlight 4中的數(shù)據(jù)綁定

開發(fā) 前端 后端
本文將為大家講述的是Silverlight 4中的數(shù)據(jù)綁定的有關(guān)內(nèi)容,希望能對(duì)大家有所幫助。

本文將為大家介紹Silverlight 4中的數(shù)據(jù)綁定,希望能對(duì)大家有所幫助。同時(shí)51CTO向您推薦《走向銀光 —— 一步一步學(xué)Silverlight》專題。

DependencyObject Binding

在Silverlight之前的版本中,其支持的元素綁定只是允許綁定繼承自FrameworkElement類下元素,但是比如一些形變比如Transformations就不能綁定了?,F(xiàn)在數(shù)據(jù)綁定也可以綁定繼承自DependencyObject下的任何元素。

 
  1.  <Grid x:Name="LayoutRoot"   
  2.  Background="White">    
  3. <StackPanel Width="400" Margin="0,22,0,0">    
  4.  <StackPanel.RenderTransform>    
  5.    <CompositeTransform    
  6.   ScaleX="{Binding Value,ElementName=stretcher}"   
  7.   ScaleY="{Binding Value,ElementName=stretcher}" />    
  8.  </StackPanel.RenderTransform>    
  9.   <Button Content="Button"/>    
  10.  <Button Content="Button"/>    
  11.  <Button Content="Button"/>    
  12.  <Button Content="Button"/>    
  13. <Button Content="Button"/>    
  14.   </StackPanel>    
  15.  <Slider Minimum=".5"   
  16.    Maximum="4"   
  17.     x:Name="stretcher"   
  18.    Value="1" VerticalAlignment="Top" />    
  19.  </Grid>  

String Formatting

新版的Silverlight4中新增加了格式化字符串的能力。在這之前如果要做一個(gè)數(shù)據(jù)格式化不得不使用一個(gè)Converter來格式化字符串。現(xiàn)在可以使用擴(kuò)展標(biāo)記StringFormat來做一些比如日期、貨幣等的格式化。

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

 
  1. <Grid x:Name="LayoutRoot" Background="White">    
  2. <TextBox Text="{Binding ReleaseDate, StringFormat='yyyy年MM月dd日',     
  3.  Mode=TwoWay}"     
  4.   Margin="0,30,0,0"    
  5.    Height="26"    
  6.     VerticalAlignment="Top" d:LayoutOverrides="Height" />    
  7. <TextBlock Text="{Binding Price, StringFormat='c'}"    
  8.  Margin="0,0,0,0"    
  9.   Height="26" VerticalAlignment="Top" />    
  10. </Grid>  

Null and Fallback Values

在某些特殊的情況下,數(shù)據(jù)有可能加載失敗。數(shù)據(jù)綁定中有新增加了兩個(gè)寬展標(biāo)記TargetNullValue、FallbackValue,TargetNullValue這個(gè)標(biāo)記表示了當(dāng)綁定值是null的時(shí)候顯示的值。FallbackValue則是在數(shù)據(jù)未綁定時(shí)顯示的值。

  1. <Grid x:Name="LayoutRoot" Background="White">    
  2. <TextBlock Text="{Binding Developer,    
  3.   TargetNullValue='(暫無)'}"     
  4.        Height="26" Margin="0,100,0,0"    
  5.       VerticalAlignment="Top" d:LayoutOverrides="Height" />    
  6.   <TextBlock Text="{Binding Publisher,     
  7.   FallbackValue='(暫無)'}" Height="26"    
  8.      VerticalAlignment="Top" Margin="0,33,0,0" />    
  9. </Grid>  
 CollectionViewSource Changes
對(duì)于在GataGrid中做分組管理,現(xiàn)在的CollectionViewSource支持?jǐn)?shù)據(jù)到GroupDescriptions的綁定,這樣可以更加輕松的在XAML做分組。
  1. <UserControl.Resources>    
  2. <CollectionViewSource x:Name="dataSource"    
  3.  Source="{Binding}">    
  4.    <CollectionViewSource.GroupDescriptions>    
  5.      <PropertyGroupDescription PropertyName="Gender" />    
  6.     <PropertyGroupDescription PropertyName="AgeGroup" />    
  7.   </CollectionViewSource.GroupDescriptions>    
  8.   <CollectionViewSource.SortDescriptions>    
  9.     <compMod:SortDescription PropertyName="AgeGroup" Direction="Ascending"/>                    
  10.     </CollectionViewSource.SortDescriptions>    
  11.    </CollectionViewSource>    
  12.  </UserControl.Resources>    
  13. <Grid x:Name="LayoutRoot" Background="White">    
  14.   <sdk:DataGrid ItemsSource="{Binding Source={StaticResource dataSource}}" />    
  15.  </Grid>  
  1. public List<Person> GetPeople()          
  2. {            List<Person> peeps = new List<Person>();  
  3.  peeps.Add(new Person() { FirstName = "Wang", LastName = "Zhe", Gender = "M", AgeGroup = "Adult" });  
  4.  peeps.Add(new Person() { FirstName = "nasa", LastName = "wang", Gender = "M", AgeGroup = "Adult" });  
  5.  peeps.Add(new Person() { FirstName = "summer", LastName = "liang", Gender = "F", AgeGroup = "Kid" });  
  6.  peeps.Add(new Person() { FirstName = "liang", LastName = "jing", Gender = "F", AgeGroup = "Kid" });  
  7.     return peeps;  
  8.         } 

Error Propogation

Silverlight的數(shù)據(jù)驗(yàn)證機(jī)制,在這里得到了很多的擴(kuò)充,提供了IDataErrorInfo、INotifyDataErrorInfo從而能得到更多的信息。

原文標(biāo)題:Silverlight 4 中數(shù)據(jù)綁定發(fā)生的變化

鏈接:http://www.cnblogs.com/nasa/archive/2010/04/19/Data_Binding_Changes_in_Silverlight_4.html

 

責(zé)任編輯:彭凡 來源: 博客園
相關(guān)推薦

2009-12-30 09:38:37

Silverlight

2009-02-20 08:54:20

DownloaderSilverlight對(duì)象

2009-12-30 09:45:52

Silverlight

2010-06-02 09:25:29

Silverlight

2009-11-26 13:12:16

Silverlight

2016-10-11 20:33:17

JavaScriptThisWeb

2009-12-31 11:10:01

2009-03-16 10:00:01

文件同步LivemeshSilverlight

2009-12-30 10:15:57

Silverlight

2012-05-28 10:34:50

MVVM 數(shù)據(jù)綁定

2009-11-18 11:33:23

Silverlight

2009-12-30 15:32:03

Silverlight

2009-12-31 16:56:40

Silverlight

2009-12-31 10:07:08

Silverlight

2009-09-07 15:25:24

MySQL數(shù)據(jù)庫互操作Silverlight

2009-12-30 09:55:51

Silverlight

2023-10-07 11:04:58

WPF數(shù)據(jù)UI

2009-09-27 10:03:53

Silverlight

2009-04-21 13:14:33

SilverlightWPF擴(kuò)展

2009-12-30 14:36:29

Silverlight
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)