XmlDataFileEditor Classe

Definição

Fornece uma interface do usuário no tempo de design para selecionar um arquivo de dados XML.Provides a design-time user interface for selecting an XML data file.

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
Herança
XmlDataFileEditor

Exemplos

O exemplo de código a seguir demonstra como associar uma instância da XmlDataFileEditor classe a uma propriedade contida em um controle personalizado.The following code example demonstrates how to associate an instance of the XmlDataFileEditor class with a property that is contained within a custom control. Quando a propriedade de controle é editada na superfície de design, a XmlDataFileEditor classe fornece a interface do usuário para selecionar e editar um nome de arquivo XML para o valor da propriedade.When the control property is edited on the design surface, the XmlDataFileEditor class provides the user interface to select and edit an XML file name for the property value.

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

Comentários

Um XmlDataFileEditor objeto é usado em tempo de design para selecionar e editar uma URL para um arquivo de dados XML (. xml) e, em seguida, atribuir a URL a uma propriedade de controle.An XmlDataFileEditor object is used at design time to select and edit a URL for an XML data file (.xml), and then assign the URL to a control property. Por exemplo, o XmlDataSource controle usa a XmlDataFileEditor classe em tempo de design para definir o valor da DataFile propriedade.For example, the XmlDataSource control uses the XmlDataFileEditor class at design time to set the value of the DataFile property.

Use o EditorAttribute atributo para associar o a XmlDataFileEditor uma propriedade.Use the EditorAttribute attribute to associate the XmlDataFileEditor with a property. Quando a propriedade associada é editada na superfície de design, o host do designer chama o EditValue método.When the associated property is edited on the design surface, the designer host calls the EditValue method. O EditValue método usa o BuildUrl método que, por sua vez, exibe uma interface do usuário para selecionar a URL e, em seguida, retorna a URL selecionada pelo usuário.The EditValue method uses the BuildUrl method, which in turn displays a user interface for selecting the URL, and then returns the URL that is selected by the user. O GetEditStyle método indica o estilo de exibição da interface do usuário.The GetEditStyle method indicates the display style of the user interface.

Derive uma classe de XmlDataFileEditor para definir um editor personalizado para uma propriedade de dados XML.Derive a class from the XmlDataFileEditor to define a custom editor for an XML data property. Por exemplo, uma classe derivada pode substituir o EditValue método e, em seguida, chamar o BuildUrl método com Filter um Caption valor personalizado.For example, a derived class can override the EditValue method, and then call the BuildUrl method with a custom Filter or Caption value.

Construtores

XmlDataFileEditor()

Inicializa uma nova instância da classe XmlDataFileEditor.Initializes a new instance of the XmlDataFileEditor class.

Propriedades

Caption

Obtém a legenda a ser exibida na caixa de diálogo de seleção.Gets the caption to display on the selection dialog box.

Filter

Obtém as opções de filtro de URL para o editor, que são usadas para filtrar os itens que aparecem na caixa de diálogo de seleção de URL.Gets the URL filter options for the editor, which is used to filter the items that appear in the URL selection dialog box.

IsDropDownResizable

Obtém um valor que indica se os editores de lista suspensa devem ser redimensionáveis pelo usuário.Gets a value indicating whether drop-down editors should be resizable by the user.

(Herdado de UITypeEditor)
Options

Obtém as opções do construtor de URL a ser usado.Gets the options for the URL builder to use.

(Herdado de UrlEditor)

Métodos

EditValue(IServiceProvider, Object)

Edita o valor do objeto especificado usando o estilo de editor indicado pelo método GetEditStyle().Edits the value of the specified object using the editor style indicated by the GetEditStyle() method.

(Herdado de UITypeEditor)
EditValue(ITypeDescriptorContext, IServiceProvider, Object)

Edita o valor do objeto especificado usando o estilo de editor fornecido pelo método GetEditStyle(ITypeDescriptorContext).Edits the value of the specified object using the editor style provided by the GetEditStyle(ITypeDescriptorContext) method.

(Herdado de UrlEditor)
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Herdado de Object)
GetEditStyle()

Obtém o estilo de editor usado pelo método EditValue(IServiceProvider, Object).Gets the editor style used by the EditValue(IServiceProvider, Object) method.

(Herdado de UITypeEditor)
GetEditStyle(ITypeDescriptorContext)

Obtém o estilo de edição do método EditValue(ITypeDescriptorContext, IServiceProvider, Object).Gets the editing style of the EditValue(ITypeDescriptorContext, IServiceProvider, Object) method.

(Herdado de UrlEditor)
GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Herdado de Object)
GetPaintValueSupported()

Indica se esse editor é compatível com pintura de uma representação do valor de um objeto.Indicates whether this editor supports painting a representation of an object's value.

(Herdado de UITypeEditor)
GetPaintValueSupported(ITypeDescriptorContext)

Indica se o contexto especificado é compatível com pintura de uma representação do valor de um objeto no contexto especificado.Indicates whether the specified context supports painting a representation of an object's value within the specified context.

(Herdado de UITypeEditor)
GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
PaintValue(Object, Graphics, Rectangle)

Pinta uma representação do valor do objeto especificado na tela especificada.Paints a representation of the value of the specified object to the specified canvas.

(Herdado de UITypeEditor)
PaintValue(PaintValueEventArgs)

Pinta uma representação do valor de um objeto usando o PaintValueEventArgs especificado.Paints a representation of the value of an object using the specified PaintValueEventArgs.

(Herdado de UITypeEditor)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Herdado de Object)

Aplica-se a

Confira também