Silverlight的绑定数据(初步学习)

刚着手学习....

xmal文件代码如下:

<UserControl x:Class="SilverlightApplication2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="600" d:DesignWidth="600">

    <Grid Background="#46461F">
        <Grid.RowDefinitions>
            <RowDefinition Height="40"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Border Grid.Row="0" Grid.Column="0" CornerRadius="15"
            Width="240" Height="36" Background="Orange"
            Margin="20 0 0 0" HorizontalAlignment="Left">
            <TextBlock Text="文章列表" Foreground="White"
                   HorizontalAlignment="Left" VerticalAlignment="Center"
                   Margin="20 0 0 0"></TextBlock>
        </Border>
        <ListBox x:Name="PostList" Grid.Column="0" Grid.Row="1"
             Margin="40 10 10 10"
             HorizontalContentAlignment="Left" VerticalContentAlignment="Bottom"
             ItemsSource="{Binding Post,Mode=OneWay}">
        </ListBox>
        <Button Margin="280,260,120,0" Width="200" Height="100" Grid.Row="1" Click="Button_Clisk" Content="点击我更改数据" FontSize="22"></Button>
    </Grid>
</UserControl>
绑定数据类:

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.ComponentModel;
namespace SilverlightApplication2
{
    public class Class1:INotifyPropertyChanged
    {
        private List<string> post;
        public List<string> Post {
            get {
                return post;
                }
            set {

                post = value;
                Notifity("Post");
            }
        
        }
        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        private void Notifity(string pro) {

            if (null != PropertyChanged)
            {
                PropertyChanged(this,new PropertyChangedEventArgs(pro));
            }
        }
    }
}

主页代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverlightApplication2;
namespace SilverlightApplication2
{
    public partial class MainPage : UserControl
    {
        Class1 cls;
        public MainPage()
        {
            InitializeComponent();
            Load();
            PostList.DataContext = cls;
        }
        private void Load() {
            cls = new Class1();
            cls.Post = new List<String> {
            "一步一步学Silverlight:使用用户控件",
            "一步一步学Silverlight :使用控件模板",
            "一步一步学Silverlight :使用样式封装控件观感",
            "一步一步学Silverlight:全屏模式支持"
            };
        }

        private void Button_Clisk(object sender, RoutedEventArgs e)
        {
            cls.Post = new List<string> { 
                 "学习怎么绑定数据:使用用户控件",
                 "学习控件的基本使用:使用控件模板",
                 "xmal的基本使用:使用样式封装控件观感",
                 "c#的学习):全屏模式支持"
            };
        }
    }
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值