XmlDataFileEditor クラス

定義

XML データ ファイルを選択するためのデザイン時ユーザー インターフェイスを提供します。

public ref class XmlDataFileEditor : System::Web::UI::Design::UrlEditor
public class XmlDataFileEditor : System.Web.UI.Design.UrlEditor
type XmlDataFileEditor = class
    inherit UrlEditor
Public Class XmlDataFileEditor
Inherits UrlEditor
継承
XmlDataFileEditor

次のコード例は、クラスの XmlDataFileEditor インスタンスをカスタム コントロール内に含まれるプロパティに関連付ける方法を示しています。 デザイン サーフェイスでコントロール プロパティを編集すると、 XmlDataFileEditor クラスは、プロパティ値の XML ファイル名を選択および編集するためのユーザー インターフェイスを提供します。

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.Design.WebControls;
using System.Web.UI.WebControls;
using System.IO;

namespace ControlDesignerSamples.CS
{
    // Define a simple text control, derived from the 
    // System.Web.UI.WebControls.Label class.
    [
        Designer(typeof(TextControlDesigner))
    ]
    public class SimpleTextControl : Label
    {
        // Define a private member to store the file name value in the control.
        private string _filename = "";
        private string _internalText = "";

        // Define the public XML data file name property.  Indicate that the
        // property can be edited at design-time with the XmlDataFileEditor class.
        [EditorAttribute(typeof(System.Web.UI.Design.XmlDataFileEditor), 
                         typeof(System.Drawing.Design.UITypeEditor))]
        public string XmlFileName
        {
            get
            {
                return _filename;
            }
            set
            {
                _filename = value;
            }
        }

        // Define a property that returns the timestamp
        // for the selected file.
        public string LastChanged
        {
            get
            {
                if ((_filename != null) && (_filename.Length > 0))
                {
                    if (File.Exists(_filename))
                    {
                        DateTime lastChangedStamp = File.GetLastWriteTime(_filename);
                        return lastChangedStamp.ToLongDateString();
                    }
                }
                return "";
            }
        }

        // Override the control Text property, setting the default
        // text to the LastChanged string value for the selected
        // file name.  If the file name has not been set in the
        // design view, then default to an empty string.
        public override string Text
        {
            get
            {
                if ((_internalText == "") && (LastChanged.Length > 0))
                {
                    // If the internally stored value hasn't been set,
                    // and the file name property has been set,
                    // return the last changed timestamp for the file.
                    _internalText = LastChanged;
                } 
                return _internalText;
            }

            set
            {
                if ((value != null) && (value.Length > 0))
                {
                    _internalText = value;
                }
                else {
                    _internalText = "";
                }
            }
        }
    }
}

Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.Design.WebControls
Imports System.Web.UI.WebControls
Imports System.IO

Namespace ControlDesignerSamples.VB


    ' Define a simple text control, derived from the 
    ' System.Web.UI.WebControls.Label class.

    <Designer(GetType(TextControlDesigner))> _
    Public Class SimpleTextControl
        Inherits Label

        ' Define a private member to store the file name value in the control.
        Private _filename As String = ""
        Private _internalText As String = ""

        ' Define the public XML data file name property.  Indicate that the
        ' property can be edited at design-time with the XmlDataFileEditor class.
        <EditorAttribute(GetType(System.Web.UI.Design.XmlDataFileEditor), _
                         GetType(System.Drawing.Design.UITypeEditor))> _
        Public Property XmlFileName() As String
            Get
                Return _filename
            End Get

            Set(ByVal value As String)
                _filename = value
            End Set
        End Property

        ' Define a property that returns the timestamp
        ' for the selected file.
        Public ReadOnly Property LastChanged() As String
            Get
                If Not _filename Is Nothing AndAlso _filename.Length > 0 Then
                    If File.Exists(_filename) Then
                        Dim lastChangedStamp As DateTime
                        lastChangedStamp = File.GetLastWriteTime(_filename)
                        Return lastChangedStamp.ToLongDateString()
                    End If
                End If

                Return String.Empty

            End Get

        End Property

        ' Override the control Text property, setting the default
        ' text to the LastChanged string value for the selected
        ' file name.  If the file name has not been set in the
        ' design view, then default to an empty string.
        Public Overrides Property Text() As String
            Get
                If _internalText.Length = 0 And LastChanged.Length > 0 Then
                    ' If the internally stored value hasn't been set,
                    ' and the file name property has been set,
                    ' return the last changed timestamp for the file.

                    _internalText = LastChanged
                End If
                Return _internalText
            End Get

            Set(ByVal value As String)
                If Not value Is Nothing AndAlso value.Length > 0 Then
                    _internalText = value
                Else
                    _internalText = String.Empty
                End If

            End Set
        End Property

    End Class
End Namespace

注釈

XmlDataFileEditorオブジェクトは、デザイン時に XML データ ファイル (.xml) の URL を選択して編集し、その URL をコントロール プロパティに割り当てるために使用されます。 たとえば、コントロールは XmlDataSource デザイン時にクラスを XmlDataFileEditor 使用してプロパティの値を DataFile 設定します。

属性を EditorAttribute 使用して、プロパティに XmlDataFileEditor 関連付けます。 関連付けられたプロパティがデザイン サーフェイスで編集されると、デザイナー ホストはメソッドを EditValue 呼び出します。 このメソッドは EditValue 、このメソッドを BuildUrl 使用して、URL を選択するためのユーザー インターフェイスを表示し、ユーザーが選択した URL を返します。 このメソッドは GetEditStyle 、ユーザー インターフェイスの表示スタイルを示します。

クラスを XmlDataFileEditor 派生して、XML データ プロパティのカスタム エディターを定義します。 たとえば、派生クラスはメソッドをEditValueオーバーライドし、カスタムFilterまたはCaption値をBuildUrl使用してメソッドを呼び出すことができます。

コンストラクター

XmlDataFileEditor()

XmlDataFileEditor クラスの新しいインスタンスを初期化します。

プロパティ

Caption

選択ダイアログ ボックスに表示するキャプションを取得します。

Filter

URL 選択ダイアログ ボックスに表示されるアイテムにフィルターをかけるための、エディターの URL フィルター オプションを取得します。

IsDropDownResizable

ユーザーがドロップダウン エディターのサイズを変更できるかどうかを示す値を取得します。

(継承元 UITypeEditor)
Options

使用する URL ビルダーのオプションを取得します。

(継承元 UrlEditor)

メソッド

EditValue(IServiceProvider, Object)

GetEditStyle() メソッドで提供されたエディター スタイルを使用して、指定したオブジェクトの値を編集します。

(継承元 UITypeEditor)
EditValue(ITypeDescriptorContext, IServiceProvider, Object)

GetEditStyle(ITypeDescriptorContext) メソッドで提供されたエディター スタイルを使用して、指定したオブジェクトの値を編集します。

(継承元 UrlEditor)
Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetEditStyle()

EditValue(IServiceProvider, Object) メソッドで使用するエディター スタイルを取得します。

(継承元 UITypeEditor)
GetEditStyle(ITypeDescriptorContext)

EditValue(ITypeDescriptorContext, IServiceProvider, Object) メソッドの編集スタイルを取得します。

(継承元 UrlEditor)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetPaintValueSupported()

エディターでオブジェクトの値の視覚的な表現を描画できるかどうかを示します。

(継承元 UITypeEditor)
GetPaintValueSupported(ITypeDescriptorContext)

指定したコンテキスト内でオブジェクトの値の視覚的な表現を描画できるかどうかを示します。

(継承元 UITypeEditor)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
PaintValue(Object, Graphics, Rectangle)

指定したキャンバスに、指定したオブジェクトの値の視覚的な表現を描画します。

(継承元 UITypeEditor)
PaintValue(PaintValueEventArgs)

指定した PaintValueEventArgs を使用して、オブジェクトの値の視覚的な表現を描画します。

(継承元 UITypeEditor)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください