XmlDataFileEditor Clase

Definición

Proporciona una interfaz de usuario en tiempo de diseño para seleccionar archivos de datos 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
Herencia
XmlDataFileEditor

Ejemplos

En el ejemplo de código siguiente se muestra cómo asociar una instancia de la XmlDataFileEditor clase con una propiedad contenida en un control personalizado. Cuando la propiedad de control se edita en la superficie de diseño, la XmlDataFileEditor clase proporciona la interfaz de usuario para seleccionar y editar un nombre de archivo XML para el valor de propiedad.

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

Comentarios

Un XmlDataFileEditor objeto se usa en tiempo de diseño para seleccionar y editar una dirección URL para un archivo de datos XML (.xml) y, a continuación, asignar la dirección URL a una propiedad de control. Por ejemplo, el XmlDataSource control usa la XmlDataFileEditor clase en tiempo de diseño para establecer el valor de la DataFile propiedad .

Utilice el EditorAttribute atributo para asociar con XmlDataFileEditor una propiedad . Cuando la propiedad asociada se edita en la superficie de diseño, el host del diseñador llama al EditValue método . El EditValue método usa el BuildUrl método , que a su vez muestra una interfaz de usuario para seleccionar la dirección URL y, a continuación, devuelve la dirección URL seleccionada por el usuario. El GetEditStyle método indica el estilo de presentación de la interfaz de usuario.

Derive una clase de XmlDataFileEditor para definir un editor personalizado para una propiedad de datos XML. Por ejemplo, una clase derivada puede invalidar el EditValue método y, a continuación, llamar al BuildUrl método con un valor o Caption personalizadoFilter.

Constructores

XmlDataFileEditor()

Inicializa una nueva instancia de la clase XmlDataFileEditor.

Propiedades

Caption

Obtiene el título que se va a mostrar en el cuadro de diálogo de selección.

Filter

Obtiene las opciones de filtro de dirección URL para el editor, que se utilizan para filtrar los elementos que aparecen en el cuadro de diálogo de selección de direcciones URL.

IsDropDownResizable

Obtiene un valor que indica si el usuario puede cambiar el tamaño de los editores desplegables.

(Heredado de UITypeEditor)
Options

Obtiene las opciones que el generador de direcciones URL va a utilizar.

(Heredado de UrlEditor)

Métodos

EditValue(IServiceProvider, Object)

Edita el valor del objeto especificado utilizando el estilo del editor indicado por el método GetEditStyle().

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

Edite el valor del objeto especificado utilizando el estilo del editor proporcionado por el método GetEditStyle(ITypeDescriptorContext).

(Heredado de UrlEditor)
Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetEditStyle()

Obtiene el estilo de editor utilizado por el método EditValue(IServiceProvider, Object).

(Heredado de UITypeEditor)
GetEditStyle(ITypeDescriptorContext)

Obtiene el estilo de edición del método EditValue(ITypeDescriptorContext, IServiceProvider, Object).

(Heredado de UrlEditor)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetPaintValueSupported()

Indica si este editor permite dibujar una representación del valor de un objeto.

(Heredado de UITypeEditor)
GetPaintValueSupported(ITypeDescriptorContext)

Indica si el contexto especificado permite dibujar una representación del valor de un objeto dentro de ese contexto.

(Heredado de UITypeEditor)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

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

Dibuja una representación del valor del objeto especificado en el lienzo indicado.

(Heredado de UITypeEditor)
PaintValue(PaintValueEventArgs)

Dibuja una representación del valor de un objeto utilizando el PaintValueEventArgs especificado.

(Heredado de UITypeEditor)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Se aplica a

Consulte también