Panel 类 移动

提供一个容器,以便在移动 Web 窗体页中组织控件。

 

C#
public class Panel : MobileControl, ITemplateable

 

 

面板是可以嵌套的容器控件。面板上的属性集由该面板中包含的控件继承。

可以使用面板实现下面的任意功能:

  • 对控件进行逻辑分组以使这些控件能够显示或隐藏。

  • 定义一个方便的容器,可以在其中动态地创建或移除控件。

  • 在面板上设置样式属性,然后使用单个点将这些属性应用于一组控件。由于样式继承适用于面板,因此面板上设置的属性也可以由该面板中包含的控件继承。

  • 向 ASP.NET 页框架提供有关分页时将哪些控件放在一起的信息。默认情况下,面板的内容保持在一页上。可以通过设置面板的 Paginate 属性修改此行为。

可以在 Panel 的文本内容中包含文本及其伴随的标记。有关更多信息,请参见 窗体标记内的文本

下面的代码示例演示如何在页加载期间设置面板属性,以及如何定义函数以操作面板属性使其能够响应命令单击。在页加载时,该代码还将在另一个面板中查找并修改设备特定的内容模板中的标签。

 

下面的代码示例演示如何在页加载期间设置面板属性,以及如何定义函数以操作面板属性使其能够响应命令单击。在页加载时,该代码还将在另一个面板中查找并修改设备特定的内容模板中的标签。

<%@ Page Language="C#"
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Drawing" %>

<script runat="server">
    public void Page_Load(Object sender, EventArgs e)
    {
        // Set Panel1 properties
        Panel1.Wrapping = Wrapping.NoWrap;
        Panel1.Alignment = Alignment.Center;
        Panel1.StyleReference = "title";

        // Find Label in Panel2
        Control ctl = Panel2.Content.FindControl("lblStatusToday");
        if (ctl != null)
            ((System.Web.UI.MobileControls.Label)ctl).Text
                = "I found this label";
    }
   
    public void MakeFontRed(Object sender, EventArgs e)
    {
        Panel1.ForeColor = Color.Red;
    }
   
    public void MakeFontBlue(Object sender, EventArgs e)
    {
        Panel1.ForeColor = Color.Blue;
    }
</script>

<html  >
<body>
<mobile:Form runat="server" id="Form1">
    <!-- First Panel -->
    <mobile:Panel runat="server" id="Panel1">
        <mobile:TextView runat="server" id="TextView1">
            A Panel provides a grouping mechanism<br />
            for organizing controls.
        </mobile:TextView>
    </mobile:Panel>
    <mobile:Command runat="server" id="Command1"  BreakAfter="false"
        Text="Make Font Red" OnClick="MakeFontRed"/>
    <mobile:Command runat="server" id="Command2" BreakAfter="true"
        Text="Make Font Blue" OnClick="MakeFontBlue"/>

    <!-- Second Panel -->
    <mobile:Panel ID="Panel2"  Runat="server">
        <mobile:DeviceSpecific id="DeviceSpecific1" runat="server">
            <!-- Filter and template for HTML32 devices -->
            <Choice Filter="isHTML32"
                Xmlns="http://schemas.microsoft.com/mobile/html32template">
                <ContentTemplate>
                    <mobile:Label id="Label1" runat="server">
                        HTML32 Template</mobile:Label>
                    <mobile:Label ID="lblStatusToday" Runat="server"/>
                </ContentTemplate>
            </Choice>
            <!-- Default filter and template -->
            <Choice>
                <ContentTemplate>
                    <mobile:Label ID="Label1" Runat="server">
                        Default Template</mobile:Label>
                    <mobile:Label ID="lblStatusToday" Runat="server" />
                </ContentTemplate>
            </Choice>
        </mobile:DeviceSpecific>
    </mobile:Panel>
</mobile:Form>
</body>
</html>

 

posted @ 2009-04-29 10:19  minmin8110  阅读(204)  评论(0)    收藏  举报