偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Silverlight單向綁定相關(guān)應(yīng)用技巧解析

開發(fā) 開發(fā)工具
Silverlight單向綁定的應(yīng)用對于初學(xué)者來說是一個(gè)比較好理解的部分。我們希望大家可以通過這篇文章介紹的例子充分掌握這一方法。

Silverlight開發(fā)工具是微軟公司在進(jìn)軍UI領(lǐng)域的一個(gè)攻堅(jiān)利器。它的出現(xiàn),改變了開發(fā)人員傳統(tǒng)的變成模式,使開發(fā)人員也能補(bǔ)通過美工來實(shí)現(xiàn)各種多媒體相關(guān)功能需求。在這里我們就先來了解下Silverlight單向綁定的一些相關(guān)概念。#t#

如果需要在數(shù)據(jù)源發(fā)生變化時(shí)能夠通知UI進(jìn)行相應(yīng)的更新,即使用Silverlight單向綁定OneWay或者雙向綁定TwoWay,則業(yè)務(wù)實(shí)體需要實(shí)現(xiàn)接口INotifyPropertyChanged。在本示例中,我們加上一個(gè)更新按鈕,當(dāng)單擊按鈕時(shí)更新user實(shí)例的屬性值,會看到界面上的數(shù)據(jù)也會發(fā)生變化。

修改一下User類,使其實(shí)現(xiàn)INotifyPropertyChanged接口。

 

  1. public class User : INotify
    PropertyChanged  
  2. {  
  3. public event PropertyChangedEven
    tHandler PropertyChanged;  
  4. private string _name;  
  5. public string Name  
  6. {  
  7. get { return _name; }  
  8. set   
  9. {  
  10. _name = value;  
  11. if(PropertyChanged != null)  
  12. {  
  13. PropertyChanged(this, new Property
    ChangedEventArgs("Name"));  
  14. }  
  15. }  
  16. }  
  17. private string _address;  
  18. public string Address  
  19. {  
  20. get { return _address; }  
  21. set   
  22. {  
  23. _address = value;  
  24. if (PropertyChanged != null)  
  25. {  
  26. PropertyChanged(this, new Property
    ChangedEventArgs("Address"));  
  27. }  
  28. }  
  29. }  

修改數(shù)據(jù)綁定模式,使用Silverlight單向綁定OneWay模式,如{Binding Address, Mode=OneWay}

  1. < Grid x:Name="LayoutRoot" 
    Background="#46461F"> 
  2. < Grid.RowDefinitions> 
  3. < RowDefinition Height="160">
  4. < /RowDefinition> 
  5. < RowDefinition Height="40">
  6. < /RowDefinition> 
  7. < RowDefinition Height="40">
  8. < /RowDefinition> 
  9. < /Grid.RowDefinitions> 
  10. < Grid.ColumnDefinitions> 
  11. < ColumnDefinition Width="150">
  12. < /ColumnDefinition> 
  13. < ColumnDefinition Width="*">
  14. < /ColumnDefinition> 
  15. < /Grid.ColumnDefinitions> 
  16. < Image Source="terrylee.jpg"
     Width="78" Height="100" 
  17. HorizontalAlignment="Left" 
    Grid.Row="0" Grid.Column="1"/> 
  18. < Button x:Name="btnUpdate" 
    Width="100" Height="40" 
  19. Content="Update" Click="btnUpdate_Click"/> 
  20. < TextBlock Foreground="White" 
    FontSize="18" Text="姓名:" 
  21. Grid.Row="1" Grid.Column="0" 
    HorizontalAlignment="Right"/> 
  22. < TextBlock x:Name="lblName" 
    Foreground="White" FontSize="18" 
  23. Grid.Row="1" Grid.Column="1" 
    HorizontalAlignment="Left" 
  24. Text="{Binding Name, Mode=OneWay}"/> 
  25. < TextBlock Foreground="White" 
    FontSize="18" Text="位置:" 
  26. Grid.Row="2" Grid.Column="0" 
    HorizontalAlignment="Right"/> 
  27. < TextBlock x:Name="lblAddress" 
    Foreground="White" FontSize="18" 
  28. Grid.Row="2" Grid.Column="1" 
    HorizontalAlignment="Left" 
  29. Text="{Binding Address, Mode=OneWay}"/> 
  30. < /Grid> 

編寫事件處理程序,為了演示把user聲明為一個(gè)全局的,并在按鈕的單擊事件中修改其屬性值:

 

  1. public partial class Page : UserControl  
  2. {  
  3. public Page()  
  4. {  
  5. InitializeComponent();  
  6. }  
  7. User user;  
  8. private void UserControl_Loaded(object 
    sender, RoutedEventArgs e)  
  9. {  
  10. user = new User();  
  11. user.Name = "TerryLee";  
  12. user.Address = "中國 天津";  
  13. lblName.DataContext = user;  
  14. lblAddress.DataContext = user;  
  15. }  
  16. private void btnUpdate_Click(object 
    sender, RoutedEventArgs e)  
  17. {  
  18. user.Name = "李會軍";  
  19. user.Address = "China Tianjin";  
  20. }  

Silverlight單向綁定的應(yīng)用方法就為大家介紹這里,希望能幫助大家提高對Silverlight這個(gè)工具的了解程度。

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

2009-12-31 16:44:53

Silverlight

2009-12-30 10:15:57

Silverlight

2009-12-29 16:08:41

Silverlight

2009-12-30 18:18:32

Silverlight

2009-12-30 10:25:03

Silverlight

2009-12-31 10:21:53

Silverlight

2009-09-15 15:40:25

C# 綁定

2010-02-26 17:51:16

Silverlight

2010-01-04 14:49:30

Silverlight

2009-12-29 17:56:47

Silverlight

2009-12-30 18:23:13

Silverlight

2009-12-30 13:37:24

Silverlight

2010-01-25 18:27:54

Android進(jìn)度條

2009-12-31 17:00:40

Silverlight

2010-01-04 14:35:55

Silverlight

2009-12-30 17:19:09

Silverlight

2009-12-31 11:15:57

Silverlight

2010-01-25 18:22:33

Android使用XM

2009-12-30 18:07:54

Silverlight

2010-01-04 16:23:42

Silverlight
點(diǎn)贊
收藏

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