(2)SilverLight程序的简单实现

新建 一个silverlight项目  添加两个工程

server工程的 代码

    <Grid x:Name="LayoutRoot" Background="Black">

    </Grid>

application的代码


    <Grid x:Name="LayoutRoot" Background="Red">

    </Grid>

启动web   很显然会出现一个black背景的网页,那第二个工程跑哪里去了?

删除Server.xap 启动,悲剧,它又回来了,还是无法指定到第二个项目的红色背景,

进入ServerTestPage.aspx 在<body> 中发现一个

 <param name="source" value="ClientBin/Server.xap"/>,这个就是制定的数据源

更改一下

 <param name="source" value="ClientBin/SilverlightApplication2.xap"/>

启动,就变成了地儿启动项了

 

 

继续,搞起

既然选择了wpf和silverlight,那就正规点,mvvm

新建一个

namespace SilverlightApplication2
{
    public class MainPageVM : INotifyPropertyChanged
    {
        private string name;
        public string Name
        {
            get { return name; }
            set
            {
                name = value;
                OnPropertyChanged(Name);
            }
        }

        private string id;
        public string ID
        {
            get { return id; }
            set
            {
                id = value;
                OnPropertyChanged(ID);
            }
        }



        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

INotifyPropertyChanged接口是通知,可以做到实时通知,具体实现,这里不做详细介绍。

实现接口,写两个属性,一个名字一个id

   public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            DataContext = new MainPageVM();
        }
    }

关联上,然后在界面写

<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="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="60"></ColumnDefinition>
            <ColumnDefinition Width="120"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        
        <TextBlock Text="用户名:"/>
        <TextBlock Grid.Row="1" Text="密  码:"/>
        <TextBox Name="fishName" Grid.Column="1" />
        <TextBox Name="fishPassword" Grid.Row="1" Grid.Column="1" />
        <Button Content="提交" Grid.Row="2" Grid.Column="1" Width="60" Click="Button_Click" HorizontalAlignment="Right"  />
    </Grid>
</UserControl>

button 有一个属性是command 可以关联 command 这个接口,但是siverlight里我没找到,这也是我觉得wpf和silverlight有区别的原因

 <Button Content="提交" Grid.Row="2" Grid.Column="1" Width="60" Command={Binding Query} HorizontalAlignment="Right"  />
query是一个属性,以后如果碰到3d动画,这里面的差距会更大,然后编译生成,你就能看到一个简答的页面了
posted @ 2012-06-27 11:54  爱喝可乐  阅读(223)  评论(0编辑  收藏  举报