DeviceSpecific クラスとは? わかりやすく解説

DeviceSpecific クラス

<DeviceSpecific> 要素内にある複数代替コンテンツからどれを選択するかを指定するコンストラクト提供します

名前空間: System.Web.UI.MobileControls
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)
構文構文

Public Class DeviceSpecific
    Inherits Control
Dim instance As DeviceSpecific
public class DeviceSpecific : Control
public ref class DeviceSpecific : public
 Control
public class DeviceSpecific extends Control
public class DeviceSpecific extends
 Control
解説解説
使用例使用例

DeviceSpecific オブジェクトと DeviceSpecificChoice オブジェクト使用してさまざまなデバイス固有のインターフェイスモバイル形式作成する方法次のコード例示します

メモメモ

次のコード サンプルはシングルファイル コード モデル使用しており、分離コード ファイル直接コピーされ場合正常に動作しない可能性あります。このコード サンプルは、拡張子.aspx の空のテキスト ファイルコピーする必要があります詳細については、「ASP.NET Web ページコード モデル」を参照してください

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

<script runat="server">
    Private Sub Form_Init(ByVal
 sender As Object, ByVal
 e As EventArgs)
        ' Create a DeviceSpecific group for Choice elements
        Dim devSpecific As New
 DeviceSpecific()
        Dim ipa As IParserAccessor

        ' Create two Choice objects, one with a filter
        For i As Integer
 = 0 To 1
            Dim devChoice As DeviceSpecificChoice
            Dim custTemplate As ITemplate

            ' Create a Choice object 
            devChoice = New DeviceSpecificChoice()
            ' Only the first Choice has a filter (must be in Web.config)
            If i = 0 Then
                devChoice.Filter = "isHTML32"

                ' Create the header template.
                custTemplate = New CustomTemplate("HeaderTemplate")
                ' Put header template in a new container
                custTemplate.InstantiateIn(New TemplateContainer())
                ' Add the header template to the Choice
                devChoice.Templates.Add("HeaderTemplate",
 custTemplate)

                ' Create the footer template
                custTemplate = New CustomTemplate("FooterTemplate")
                ' Put footer template in a new container
                custTemplate.InstantiateIn(New TemplateContainer())
                ' Add the footer template to the Choice
                devChoice.Templates.Add("FooterTemplate",
 custTemplate)
            End If
            
            ' Add the Choice to the DeviceSpecific
            ipa = CType(devSpecific, IParserAccessor)
            ipa.AddParsedSubObject(devChoice)
        Next

        ' Add the DeviceSpecific object to the form
        ipa = CType(Form1, IParserAccessor)
        ipa.AddParsedSubObject(devSpecific)
    End Sub

    Protected Sub Page_Load(ByVal
 sender As Object, _
        ByVal e As EventArgs)

        Dim lab As System.Web.UI.MobileControls.Label
        lab = CType(Form1.Header.FindControl("Label1"),
 _
            System.Web.UI.MobileControls.Label)
        If IsNothing(lab) Then Return

        ' Get the selected choice's filter name
        Dim filterName As String
 = _
        Form1.DeviceSpecific.SelectedChoice.Filter
        If filterName = "isHTML32"
 Then
            lab.Text += " - HTML32"
        Else
            lab.Text += " - Default"
        End If
    End Sub

    Public Class CustomTemplate
        Implements ITemplate
        Dim templName As String

        ' Constructor
        Public Sub New(ByVal
 TemplateName As String)
            templName = TemplateName
        End Sub

        Public Sub InstantiateIn(ByVal
 container As Control) _
            Implements ITemplate.InstantiateIn
            
            If templName = "HeaderTemplate"
 Then
                ' Create a label
                Dim lab As New
 System.Web.UI.MobileControls.Label
                lab.Text = "Header Template"
                lab.ID = "Label1"

                ' Create a command
                Dim cmd As New
 Command()
                cmd.Text = "Submit"

                ' Add controls to the container
                container.Controls.Add(lab)
                container.Controls.Add(cmd)
            
            ElseIf templName = "FooterTemplate"
 Then
                ' Create a label
                Dim lab As System.Web.UI.MobileControls.Label
                lab = New System.Web.UI.MobileControls.Label()
                lab.ID = "Label2"
                lab.Text = "Footer Template"

                ' Add label to the container
                container.Controls.Add(lab)
            End If
        End Sub
    End Class

</script>

<html xmlns="http:'www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="Form1" runat="server"
 
        OnInit="Form_Init">
    </mobile:form>
</body>
</html>
<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
    private void Form_Init(object sender, System.EventArgs
 e)
    {
        // Create a DeviceSpecific group for Choice elements
        DeviceSpecific devSpecific = new DeviceSpecific();

        // Create two Choice objects, one with a filter
        for (int i = 0; i < 2; i++)
        {
            DeviceSpecificChoice devChoice;
            ITemplate custTemplate;

            // Create a Choice object 
            devChoice = new DeviceSpecificChoice();
            // Only the first Choice has a filter (must be in Web.config)
            if (i == 0)
                devChoice.Filter = "isHTML32";

            // Create the header template.
            custTemplate = new CustomTemplate("HeaderTemplate");
            // Put header template in a new container
            custTemplate.InstantiateIn(new TemplateContainer());
            // Add the header template to the Choice
            devChoice.Templates.Add("HeaderTemplate", custTemplate);

            // Create the footer template
            custTemplate = new CustomTemplate("FooterTemplate");
            // Put footer template in a new container
            custTemplate.InstantiateIn(new TemplateContainer());
            // Add the footer template to the Choice
            devChoice.Templates.Add("FooterTemplate", custTemplate);

            // Add the Choice to the DeviceSpecific
            ((IParserAccessor)devSpecific).AddParsedSubObject(devChoice);
        }

        // Add the DeviceSpecific object to the form
        ((IParserAccessor)Form1).AddParsedSubObject(devSpecific);
    }

    protected void Page_Load(object sender,
 EventArgs e)
    {
        System.Web.UI.MobileControls.Label lab;
        lab = (System.Web.UI.MobileControls.Label)Form1.Header.FindControl("Label1");
        if (lab == null)
            return;

        // Get the selected choice's filter name
        string filterName = 
            Form1.DeviceSpecific.SelectedChoice.Filter;
        if (filterName == "isHTML32")
            lab.Text += " - HTML32";
        else
            lab.Text += " - Default";
    }

    public class CustomTemplate : ITemplate
    {
        String templateName;

        // Constructor
        public CustomTemplate(string TemplateName)
        {
            templateName = TemplateName;
        }

        public void InstantiateIn(Control container)
        {
            if (templateName == "HeaderTemplate")
            {
                // Create a label
                System.Web.UI.MobileControls.Label lab;
                lab = new System.Web.UI.MobileControls.Label();
                lab.Text = "Header Template";
                lab.ID = "Label1";

                // Create a command
                Command cmd = new Command();
                cmd.Text = "Submit";

                // Add controls to the container
                container.Controls.Add(lab);
                container.Controls.Add(cmd);
            }
            else if (templateName == "FooterTemplate")
            {
                // Create a label
                System.Web.UI.MobileControls.Label lab;
                lab = new System.Web.UI.MobileControls.Label();
                lab.ID = "Label2";
                lab.Text = "Footer Template";

                // Add label to the container
                container.Controls.Add(lab);
            }
        }
    }
</script>

<html  >
<body>
    <mobile:form id="Form1" runat="server" OnInit="Form_Init">
    </mobile:form>
</body>
</html>

上記コードはすべて、宣言によって次のマークアップ置換できます

<html  >
<body>
    <mobile:Form id="Form1"
 runat="server">
        <mobile:DeviceSpecific Runat="server">
            <Choice Filter="isHTML32">
                <HeaderTemplate>
                    <mobile:Label ID="Label1"
 Runat="server">
                        Header Template - HTML32</mobile:Label>
                    <mobile:Command Runat="server">
                        Submit</mobile:Command>
                </HeaderTemplate>
                <FooterTemplate>
                    <mobile:Label ID="Label2"
 Runat="server">
                        Footer Template</mobile:Label>
                </FooterTemplate>
            </Choice>
            <Choice>
                <HeaderTemplate>
                    <mobile:Label ID="Label1"
 Runat="server">
                        Header Template - Default</mobile:Label>
                    <mobile:Command ID="Command1"
 Runat="server">
                        Submit</mobile:Command>
                </HeaderTemplate>
                <FooterTemplate>
                    <mobile:Label ID="Label2"
 Runat="server">
                        Footer Template</mobile:Label>
                </FooterTemplate>
            </Choice>
        </mobile:DeviceSpecific>
    </mobile:Form>
</body>
</html>

これらの例では、Web.config ファイル次の要素が必要です。

<!-- In Web.config file -->
<deviceFilters>
  <filter name="isHTML32" compare="PreferredRenderingType"
 argument="html32" />
</deviceFilters>
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
    System.Web.UI.MobileControls.DeviceSpecific
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DeviceSpecific クラス」の関連用語

DeviceSpecific クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DeviceSpecific クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS