XAML C#
<Button Content="农国苏" Click="Button_Click" /> System.Windows.Controls.Button ngsButton = new System.Windows.Controls.Button();
    ngsButton.Content = "农国苏";
    ngsButton.Click += new System.Windows.RoutedEventHandler(Button_Click);
    <Button>
       <Button.Content>
          <Rectangle Height="80" Width="40" Fill="Black" />
       </Button.Content>
    </Button>
    System.Windows.Controls.Button ngsButton = new System.Windows.Controls.Button();
    System.Windows.Shapes.Rectangle ngsRectangle = new System.Windows.Shapes.Rectangle();
    ngsRectangle.Width = 40;
    ngsRectangle.Height = 80;
    ngsRectangle.Fill = System.Windows.Media.Brushes.Black;
    ngsButton.Content = ngsRectangle;
    <ListBox>
       <ListBox.Items>
          <ListBoxItem Content="农国苏1" />
          <ListBoxItem Content="农国苏2" />
       </ListBox.Items>
    </ListBox>
    System.Windows.Controls.ListBox ngsListBox = new System.Windows.Controls.ListBox();
    System.Windows.Controls.ListBoxItem ngsItem1 = new System.Windows.Controls.ListBoxItem();
    System.Windows.Controls.ListBoxItem ngsItem2 = new System.Windows.Controls.ListBoxItem();
    ngsItem1.Content = "农国苏1";
    ngsItem2.Content = "农国苏2";
    ngsListBox.Items.Add(ngsItem1);
    ngsListBox.Items.Add(ngsItem2);
    <ResourceDictionary>
       <Color x:Key="key1" A="255" R="255" G="255" B="255" />
       <Color x:Key="key2" A="0" R="0" G="0" B="0" />
    </ResourceDictionary>

System.Windows.ResourceDictionary ngsDictionary = new System.Windows.ResourceDictionary();

    System.Windows.Media.Color ngsColor1 = new System.Windows.Media.Color();
    System.Windows.Media.Color ngsColor2 = new System.Windows.Media.Color();

    ngsColor1.A = 255;
    ngsColor1.R = 255;
    ngsColor1.G = 255;
    ngsColor1.B = 255;

    ngsColor2.A = 0;
    ngsColor2.R = 0;
    ngsColor2.G = 0;
    ngsColor2.B = 0;

    ngsDictionary.Add("key1" ngsColor1);
    ngsDictionary.Add("key2" ngsColor2);

posted @ 2008-07-03 23:24 农国苏 阅读(101) | 评论 (0)编辑

内容控件:
1.Button:
当Button.IsCancel="True"时,点击按钮,对话框关闭。当Button.IsDefault="True",按回车触发按钮的Click事件。
2.RepeatButton:
外表和Button一模一样,行为也基本一样,不一样的地方是,当按住RepeatButton不放时,不断触发点击事件。其触发事件频率由属性Delay和Interval决定。同时RepeatButton没有取消和默认这两种行为。
3.ToggleButton:
外表和Button一模一样,也没有取消和默认这两种行为,我把它称为“凹凸”按钮,按一下“凹”了(IsChecked属性为true)再按一下“凸”了(IsChecked属性为false)。
4.CheckBox:
CheckBoxt和ToggleButton只有外表上的差别。
5.RadioButton:
把RadioButton放在一个组里,一次只有一个可以被选中,就是所谓的“互斥性”,但不能通过选中本身来取消对自己的选中(CheckBox可以),可以通过编程的方式来完成。
简单容器:
1.Label:
可以用Content属性(非text属性)存储任何内容(如:Button Menu等),但Label只对文本有用。
2.ToolTip:
把内容放在浮动框中,但它必须赋给另一个元素的ToolTip属性,不能直接放在UI元素树中。
3.Frame:
WPF的Frame的行为很像HTML的Frame,也可以包含任何内容,如果同时设置了Source和Content属性,Content优先。
有Header的容器:
1.GroupBox:
GroupBox通常含多个项,也可以只包含一个项,Header属性和Content属性一样可以包含任意对象(如:Button)。
2.Expander:
Expander和GroupBox相似,但Expander可以展开或折叠(默认折叠),Expander中的按钮实际上是ToggleButton,只是换了UI而已。
Items控件
1.ComboBox:
ComboBox隐式地把它每一个项包含在ComboBoxItem对象中,当然也可以显式地在一个ComboBoxItem中包含任何一个Item,ComboBoxItem也是一个内容控件。ComboBox允许用户在选择框里输入文字,如果文字和已有的Item一样,且其被选中,否则不选中任何Item,但文字被存储在Text属性中。
2.ListBox:
ListBox和ComboBox类似,但ListBox内的所有项都会显示出来,或以滚动条的方式显示出来。
3.ListView:
ListView和ListBox很象,ListView提供View属性来自定义视图模板。
4.TabControl:
用它可以在多个页面之间进行切换。
菜单
1.Menu:
Menu是水平放置它的项,Menu中的项可以是任何东西,但建议使用MenuItem和Separator(分隔线)对象。
2.ContextMenu(上下文菜单):
和Menu工作原理一样,但不能直接放在元素树中,只能通过属性把它加载到别的控件上。当用户在该控件上右击时,菜单就显示出来。
3.TreeView:
通过展开/折叠节点来分层显示数据。
4.ToolBar:
主要是对许多小按钮或其它控件进行分组。
5.StatusBar:
也是以水平方式放置它的项,通常用来在窗口底部显示状态信息。
Range控件
1.ProgressBar:
显示进度的控件。
2.Slider:
可以通过在刻度尺移动“游标”来改变当前值。
文本控件
1.TextBox:
能输入一行或多行文字,内容存储在Text属性(不是Content属性)中。
2.RichTextBox:
RichTextBox是高级版的TextBox,能包含格式化的文字,内容存在Document(FlowDocument类型)属性(不是Text属性)里,
3.PasswordBox:
PasswordBox是简单的TextBox,以小圆点的方式显示输入的文字(密码嘛!当然不能让你看见)。
4.InkCanvas:
通过鼠标或指示笔进行书写或画画的控件。(指示笔:笔尖用来写,笔端和来擦)
布局控件
1.Canvas:
控件里的元素通过坐标的方式定位。
2.StackPanel:
控件里的元素以从左到右的方式或从上到下的方式排列。
3.WrapPanel:
WrapPanel与StackPanel相似,区别在于当空间不够时元素会自己换行或换列。
4.DockPanel:
我把它称为“磁铁”控件,它可以让元素“吸附”在某一条边上。并拉伸元素以填满全部宽度或高度。
5.Grid:
类似HTML中的table。
6.TabPanel:
简化的WrapPanel。
7.ToolBarOverflowPanel:
也是简化的WrapPanel。
8.ToolBarTray:
仅支持ToolBar的子元素,并以水平方式排列ToolBar。
9.UniformGrid:
是简化的Grid,所有行和列的大小设置都是*,且不能改变。
10.ScrollBar:
以滚屏的方式显示其内容。
11.ViewBox:
ViewBox只能有一个子元素,默认情况下,ViewBox会向两个方向拉伸,来提供它的内容足够的空间。但也提供一个Stretch属性来控制其唯一的子元素在它的边界内缩放。


 

posted @ 2008-07-03 22:32 农国苏 阅读(427) | 评论 (8)编辑

第一步(在页面上创建“输入”和“输出”区域)Default.aspx:
<form id="form1" runat="server">
    <div>
        输入:<input id="A" type="text" value="0" onkeyup="Count();" />
        输入:<input id="B" type="text" value="0" onkeyup="Count();" />
        输出:<input id="C" type="text" value="0" />
    </div>
</form>
第二步(创建XMLHttpRequest对象)Default.aspx:
var xmlHttp;
function createXMLHttpRequest()
{
   if(window.ActiveXObject)
   {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
   }
   else if(window.XMLHttpRequest)
   {
       xmlHttp = new XMLHttpRequest();
   }
}
第三步(创建发布请求的方法)Default.aspx:
function Count()
{
   url = "Handler.ashx?A=" + document.getElementById('A').value + "&B=" + document.getElementById('B').value;
   xmlHttp.open("GET",url,true);
   xmlHttp.onreadystatechange=doUpdate;
   xmlHttp.send();
   return false;
}
第四步(创建更新页面的方法)Default.aspx:
function doUpdate()
{
   if(xmlHttp.readyState==4)
   {
      document.getElementById('C').value=xmlHttp.responseText;
   }
}
第五步(创建后台处理请求)Handler.ashx:
public void ProcessRequest(HttpContext context)
{
    int a = 0;
    int b = 0;
    if (context.Request.QueryString["A"] != null)
    {
        a = Convert.ToInt16(context.Request.QueryString["A"].ToString());
    }
    if (context.Request.QueryString["B"] != null)
    {
        b = Convert.ToInt16(context.Request.QueryString["B"].ToString());
    }
    context.Response.Write(a + b);
}
前台Default.aspx完整代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>Ajax的核心</title>

    <script type="text/javascript">
    var xmlHttp;
    function createXMLHttpRequest()
    {
       if(window.ActiveXObject)
       {
          xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       else if(window.XMLHttpRequest)
       {
          xmlHttp = new XMLHttpRequest();
       }
    }
    function Count()
    {
       url = "Handler.ashx?A=" + document.getElementById('A').value + "&B=" + document.getElementById('B').value;
       xmlHttp.open("GET",url,true);
       xmlHttp.onreadystatechange=doUpdate;
       xmlHttp.send();
       return false;
    }
    function doUpdate()
    {
       if(xmlHttp.readyState==4)
       {
          document.getElementById('C').value=xmlHttp.responseText;
       }
    }
    </script>

</head>
<body onload="createXMLHttpRequest();">
    <form id="form1" runat="server">
    <div>
        输入:<input id="A" type="text" value="0" onkeyup="Count();" />
        输入:<input id="B" type="text" value="0" onkeyup="Count();" />
        输出:<input id="C" type="text" value="0" />
    </div>
    </form>
</body>
</html>

后台Handler.ashx完整代码:
<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        int a = 0;
        int b = 0;
        if (context.Request.QueryString["A"] != null)
        {
            a = Convert.ToInt16(context.Request.QueryString["A"].ToString());
        }
        if (context.Request.QueryString["B"] != null)
        {
            b = Convert.ToInt16(context.Request.QueryString["B"].ToString());
        }
        context.Response.Write(a + b);
    }

    public bool IsReusable
    {
        get
        {
            return true;
        }
    }

}

XMLHttpRequest对象方法:
abort():停止当前请求。
getAllResponseHeaders():将HTTP请求的所有响应首部作为键/值对返回。
getResponsHeader("headerLabel"):返回指定首部的字符串值。
open("method","URL"[,asyncFlag[,"userName"[,"password"]]]):建立对服务器的调用,method可以是GET POST PUT URL可以是相对URL或绝对URL。3个可选参数为:1.asyncFlag:是否非同步标记2.userName:用户名3.password:密码。
send(content):向服务器发出请求
setRequestHeader("label","value"):把指定首部设置为所提供的值,在调用该方法之前必须先调用open方法。
XMLHttpRequest对象属性:
onreadystatechange:状态改变的事件触发器,每个状态改变都会触发事件触发器。
readyState:对象状态,0=未初始化,1=正在加载,2=已加载,3=交互中,4=完成。
responseText:服务器的响应,字符串。
responseXML:服务器的响应,XML。该对象可以解析为一个DOM对象。
status:服务器返回的HTTP状态码。
statusText:HTTP状态码的相应文本。

posted @ 2008-07-03 18:27 农国苏 阅读(756) | 评论 (4)编辑

第一步(在页面上创建“输入”和“输出”区域):myPage.aspx
<form id="form1" runat="server">
   <div>
       输入姓名:<input id="txtUserName" type="text" />
       输出信息:<span id="Results" ></span>
   </div>
</form>
第二步(分别创建两个javascript方法通过DOM控制“输入”和“输出”):myPage.aspx
<script type="text/JavaScript">
    function DoSearch()
    {
        var txtFirstName = document.getElementById("txtUserName");
        CallServer(txtFirstName.value, "");
    }
   
    function ReceiveServerData(txtUserInfo)
    {
        Results.innerText = txtUserInfo;
    }
   
    setInterval('DoSearch()',1000);
</script>
第三步(在后台注册CallServer和ReceiveServerData):myPage.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
  
  String cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
  String callbackScript;
  callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + "} ;";
  //注册JavaScript
  Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
}
第四步(后台继承ICallbackEventHandler并实现RaiseCallbackEvent()和GetCallbackResult())
//引发Callback事件处理
public partial class myPage : System.Web.UI.Page,ICallbackEventHandler
{
   protected string txtUserInfo;//信息

   public void RaiseCallbackEvent(string txtFirstName)
   { 
       txtUserInfo="信息";
   }
   //返回Callback结果
   public string GetCallbackResult()
   {
      return txtUserInfo; //返回信息
   }
}
前台myPage.aspx完整代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page.aspx.cs" Inherits="myPage" %>

<!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>Page</title>
    <script type="text/JavaScript">
    function DoSearch()
    {
        var txtFirstName = document.getElementById("txtUserName");
        CallServer(txtFirstName.value, "");
    }
   
    function ReceiveServerData(txtUserInfo)
    {
        Results.innerText = txtUserInfo;
    }
   
    setInterval('DoSearch()',1000);
  </script>

</head>
<body>
   <form id="form1" runat="server">
      <div>
         输入姓名:<input id="txtUserName" type="text" />
         输出信息:<span id="Results" ></span>
      </div>
   </form>
</body>
</html>

后台myPage.aspx.cs完整代码:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class myPage : System.Web.UI.Page,ICallbackEventHandler
{
   protected string txtUserInfo;//信息

   protected void Page_Load(object sender, EventArgs e)
   {
  
      String cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
      String callbackScript;
      callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + "} ;";

      //注册JavaScript
      Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
   }

   public void RaiseCallbackEvent(string txtFirstName)
   { 
       txtUserInfo="信息";
   }
   //返回Callback结果
   public string GetCallbackResult()
   {
      return txtUserInfo; //返回信息
   }
}

posted @ 2008-07-03 15:10 农国苏 阅读(662) | 评论 (3)编辑

一.使用RegisterStartUpScript注册只执行一次的javascript
第1步(创建并注册并使用javascript):Page.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
     //创建JavaScript
     string info = "<script>alert('你好,我是农国苏!')</script>";

     //判断Welcome是否已被注册
     if (!Page.ClientScript.IsStartupScriptRegistered("Welcome"))
     {
         //动态注册并执行JavaScript
         Page.ClientScript.RegisterStartupScript(this.GetType(), "Welcome", info);
     }
 }
二.使用RegisterClientScriptBlock注册javascript
第1步(创建并注册javascript):Page.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
     //创建JavaScript
     string info="";
     info += "function showName(username)";
     info += "{ alert('您的名字是:'+ username); }";  

    //判断myName是否已被注册
    if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "myName"))
    {
    //动态注册JavaScript
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "myName", info,true);
     }
 }
第2步(调用javascript):Page.aspx
<form id="form1" runat="server">
   <div>
        姓名:<input id="txtUserName" type="text" />
        <input id="btnSubmit" type="button" value="确定" onclick="showName(txtUserName.value)" />
   </div>
</form>
三.使用RegisterClientScriptInclude注册javascript
第1步(创建javascript):Script/Info.js
function showName(username)
{
    alert('您的姓名是:'+username);
}
第2步(调用javascript):Page.aspx
<form id="form1" runat="server">
   <div>

      姓名:<input id="txtUserName" type="text" />
      <input id="btnSubmit" type="button" value="确定" onclick="showName(txtUserName.value)" />
   </div>
</form>
第3步(注册javascript):Page.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
    //判断是否已被注册
    if (!ClientScript.IsClientScriptIncludeRegistered(this.GetType(), "myMessage"))
    {
     //动态注册JavaScript
     Page.ClientScript.RegisterClientScriptInclude("myMessage", "Script/Info.js");
    }
}

posted @ 2008-07-03 11:05 农国苏 阅读(1623) | 评论 (19)编辑