zoukankan      html  css  js  c++  java
  • Silverlight学习笔记一(理解一下机制,使用一下布局,实现一个简单的用户登录)

    今天把silverlight入了个门,主要是转变一下思想,跟flash的开发有点类似,跟java的applet有点类似。
    下面是几点总结:

    1.Silverlight应用不能够独立运行,选择创建一个ASP.NET Web Site或者Web

    Application Project用来托管Silverlight应用程序。

    2.Silverlight项目默认包括两个项目,
    一个是类库项目:FirstSilverlight
    一个是网站项目:FirstSilverlight.Web

    3.Silverlight不能直接右击.aspx点浏览,需要运行。

    4.Silverlight中的Page.xaml就相当于flash的一个场景,
    进入这里之后,你在这里执行你的动作,忘记.aspx页面的方式。
    不要考虑着提交到哪个页面,只管在这个页面里写程序。
    比如登录了,进入登录后的页面,可以把登录界面的控件隐藏了。
    把登录后界面的控件显示出来。
    参考李会军的入门系列:http://www.cnblogs.com/Terrylee/archive/2008/03/07/Silverlight2-step-by-step-part1.html

    Page.xaml代码如下,这里相当于flash开发:

    代码
    <UserControl x:Class="FirstSilverlight.Page"
        xmlns
    ="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x
    ="http://schemas.microsoft.com/winfx/2006/xaml" 
        Width
    ="800" Height="600">
        
    <Grid x:Name="LayoutRoot" Background="#46461F" ShowGridLines="True"><!--相当于table-->
            
    <Grid.RowDefinitions>
                
    <RowDefinition Height="50"/><!--这里定义行,相当于tr-->
                
    <RowDefinition Height="*"/>
                
    <RowDefinition Height="*"/>
            
    </Grid.RowDefinitions>
            
    <Grid.ColumnDefinitions>
                
    <ColumnDefinition Width="100"/><!--这里定义列,相当于td-->
                
    <ColumnDefinition Width="*"/>
            
    </Grid.ColumnDefinitions>
            
    <!--这里不用再用<td></td>包起来了, Grid.Row="2" Grid.Column="1" 这样子定义行列-->
                
    <TextBlock Grid.Row="0" Grid.Column="0" Text="UserName:" VerticalAlignment="Center" Foreground="White"></TextBlock>
            
    <TextBlock Grid.Row="1" Grid.Column="0" Text="Password:" VerticalAlignment="Center" Foreground="White"></TextBlock>
            
    <TextBox x:Name="txtUserName" Grid.Row="0" Grid.Column="1" Width="200" Height="30" HorizontalAlignment="Left"></TextBox>
            
    <TextBox x:Name="txtPwd" Grid.Row="1" Grid.Column="1" Width="200" Height="30" HorizontalAlignment="Left"></TextBox>
            
    <Button x:Name="myButton" Content="登录" Width="240" Height="100" Click="myButton_Click" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left"></Button>
            
        
    </Grid>
            
            
    </UserControl>

    Page.xaml.cs代码如下:

    代码
    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;

    namespace FirstSilverlight
    {
        
    public partial class Page : UserControl
        {
            
    public Page()
            {
                InitializeComponent();
            }

            
    private void myButton_Click(object sender, RoutedEventArgs e)
            {
                
    //this.myButton.Content = "Clicked";
                
    //this.myButton.Background = new SolidColorBrush(Colors.Red);
                if (txtUserName.Text == "admin" && txtPwd.Text == "admin123")
                {
                    txtUserName.Visibility 
    = System.Windows.Visibility.Collapsed;
                    txtPwd.Visibility 
    = System.Windows.Visibility.Collapsed;
                }

            }
        }
    }

    在Default.aspx页面中引入Silverlight场景,代码如下:

    代码
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="FirstSilverlight.Web._Default" %>
    <%--这里添加声明--%>
    <%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls" TagPrefix="asp" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        
    <title></title>
    </head>
    <body>
        
    <form id="form1" runat="server">
        
    <div>
        
    <%--这里添加引用--%>
        
    <asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/FirstSilverlight.xap" Version="2.0" Width="100%" Height="100%" />
        
    </div>
        
    </form>
    </body>
    </html>

    源码下载:https://files.cnblogs.com/greatverve/FirstSilverlight.rar

  • 相关阅读:
    给router-link 标签添加事件@click 、@mouseover等无效
    elementUI的导航栏在刷新页面的时候选中状态消失的解决
    查看mysql数据库中的所有用户
    已经安装了客户端,但是cmd输入sqlcmd报错:Sqlcmd:Error:Connection failure.SQL Native Client is not installed correctly
    在运行bat文件时,报错发生系统错误123,文件名,目录名或卷标语法不正确
    数据库表空间文件被删除后,再删除表空间时报错
    oracle在exp导出时报错PLS-00201: identifier 'EXFSYS.DBMS_EXPFIL_DEPASEXP' must be declared
    oracle compile 编译无效对象
    Oracle 导出错误 EXP-00000~EXP-00107
    修改oralce数据库用户名和密码
  • 原文地址:https://www.cnblogs.com/greatverve/p/1731164.html
Copyright © 2011-2022 走看看