XmlDataFileEditor Klasa
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
Udostępnia interfejs użytkownika czasu projektowania do wybierania pliku danych 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
- Dziedziczenie
Przykłady
W poniższym przykładzie kodu pokazano, jak skojarzyć wystąpienie XmlDataFileEditor klasy z właściwością zawartą w kontrolce niestandardowej. Gdy właściwość kontrolki jest edytowana na powierzchni projektowej, XmlDataFileEditor klasa udostępnia interfejs użytkownika do wybierania i edytowania nazwy pliku XML dla wartości właściwości.
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
Uwagi
Obiekt XmlDataFileEditor jest używany w czasie projektowania do wybierania i edytowania adresu URL pliku danych XML (.xml), a następnie przypisania adresu URL do właściwości kontrolki. Na przykład kontrolka XmlDataSource używa XmlDataFileEditor klasy w czasie projektowania, aby ustawić wartość DataFile właściwości.
Użyj atrybutu EditorAttribute , aby skojarzyć właściwość XmlDataFileEditor z właściwością. Gdy skojarzona właściwość jest edytowana na powierzchni projektowej, host projektanta wywołuje metodę EditValue . Metoda EditValue używa BuildUrl metody , która z kolei wyświetla interfejs użytkownika do wybierania adresu URL, a następnie zwraca adres URL wybrany przez użytkownika. Metoda GetEditStyle wskazuje styl wyświetlania interfejsu użytkownika.
Utwórz klasę z XmlDataFileEditor klasy , aby zdefiniować edytor niestandardowy dla właściwości danych XML. Na przykład klasa pochodna może zastąpić metodę EditValue , a następnie wywołać BuildUrl metodę przy użyciu wartości niestandardowej Filter lub Caption .
Konstruktorów
| Nazwa | Opis |
|---|---|
| XmlDataFileEditor() |
Inicjuje nowe wystąpienie klasy XmlDataFileEditor. |
Właściwości
| Nazwa | Opis |
|---|---|
| Caption |
Pobiera podpis do wyświetlenia w oknie dialogowym wyboru. |
| Filter |
Pobiera opcje filtru adresu URL edytora, które są używane do filtrowania elementów wyświetlanych w oknie dialogowym wyboru adresu URL. |
| IsDropDownResizable |
Pobiera wartość wskazującą, czy edytory listy rozwijanej powinny być możliwe do zmiany rozmiaru przez użytkownika. (Dziedziczone od UITypeEditor) |
| Options |
Pobiera opcje do użycia przez konstruktora adresów URL. (Dziedziczone od UrlEditor) |
Metody
| Nazwa | Opis |
|---|---|
| EditValue(IServiceProvider, Object) |
Edytuje wartość określonego obiektu przy użyciu stylu edytora wskazanego przez metodę GetEditStyle() . (Dziedziczone od UITypeEditor) |
| EditValue(ITypeDescriptorContext, IServiceProvider, Object) |
Edytuje wartość określonego obiektu przy użyciu stylu edytora dostarczonego przez metodę GetEditStyle(ITypeDescriptorContext) . (Dziedziczone od UrlEditor) |
| Equals(Object) |
Określa, czy dany obiekt jest taki sam, jak bieżący obiekt. (Dziedziczone od Object) |
| GetEditStyle() |
Pobiera styl edytora używany przez metodę EditValue(IServiceProvider, Object) . (Dziedziczone od UITypeEditor) |
| GetEditStyle(ITypeDescriptorContext) |
Pobiera styl edycji EditValue(ITypeDescriptorContext, IServiceProvider, Object) metody . (Dziedziczone od UrlEditor) |
| GetHashCode() |
Służy jako domyślna funkcja skrótu. (Dziedziczone od Object) |
| GetPaintValueSupported() |
Wskazuje, czy ten edytor obsługuje malowanie reprezentacji wartości obiektu. (Dziedziczone od UITypeEditor) |
| GetPaintValueSupported(ITypeDescriptorContext) |
Wskazuje, czy określony kontekst obsługuje malowanie reprezentacji wartości obiektu w określonym kontekście. (Dziedziczone od UITypeEditor) |
| GetType() |
Type Pobiera wartość bieżącego wystąpienia. (Dziedziczone od Object) |
| MemberwiseClone() |
Tworzy płytkią kopię bieżącego Objectelementu . (Dziedziczone od Object) |
| PaintValue(Object, Graphics, Rectangle) |
Maluje reprezentację wartości określonego obiektu na określoną kanwę. (Dziedziczone od UITypeEditor) |
| PaintValue(PaintValueEventArgs) |
Maluje reprezentację wartości obiektu przy użyciu określonego PaintValueEventArgsobiektu . (Dziedziczone od UITypeEditor) |
| ToString() |
Zwraca ciąg reprezentujący bieżący obiekt. (Dziedziczone od Object) |