TypeConverter.ConvertFrom TypeConverter.ConvertFrom TypeConverter.ConvertFrom TypeConverter.ConvertFrom Method

定義

會將指定值轉換為這個轉換子的型別。Converts the given value to the type of this converter.

多載

ConvertFrom(Object) ConvertFrom(Object) ConvertFrom(Object) ConvertFrom(Object)

會將指定值轉換為這個轉換子的型別。Converts the given value to the type of this converter.

ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) ConvertFrom(ITypeDescriptorContext, CultureInfo, Object)

使用指定的內容和文化特性資訊,將指定物件轉換為這個轉換子的類型。Converts the given object to the type of this converter, using the specified context and culture information.

ConvertFrom(Object) ConvertFrom(Object) ConvertFrom(Object) ConvertFrom(Object)

會將指定值轉換為這個轉換子的型別。Converts the given value to the type of this converter.

public:
 System::Object ^ ConvertFrom(System::Object ^ value);
public object ConvertFrom (object value);
member this.ConvertFrom : obj -> obj
Public Function ConvertFrom (value As Object) As Object

參數

value
Object Object Object Object

要進行轉換的 ObjectThe Object to convert.

傳回

Object,代表轉換過的值。An Object that represents the converted value.

例外狀況

無法執行轉換作業。The conversion cannot be performed.

ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) ConvertFrom(ITypeDescriptorContext, CultureInfo, Object)

使用指定的內容和文化特性資訊,將指定物件轉換為這個轉換子的類型。Converts the given object to the type of this converter, using the specified context and culture information.

public:
 virtual System::Object ^ ConvertFrom(System::ComponentModel::ITypeDescriptorContext ^ context, System::Globalization::CultureInfo ^ culture, System::Object ^ value);
public virtual object ConvertFrom (System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value);
abstract member ConvertFrom : System.ComponentModel.ITypeDescriptorContext * System.Globalization.CultureInfo * obj -> obj
override this.ConvertFrom : System.ComponentModel.ITypeDescriptorContext * System.Globalization.CultureInfo * obj -> obj
Public Overridable Function ConvertFrom (context As ITypeDescriptorContext, culture As CultureInfo, value As Object) As Object

參數

culture
CultureInfo CultureInfo CultureInfo CultureInfo

要用作目前文化特性的 CultureInfoThe CultureInfo to use as the current culture.

value
Object Object Object Object

要進行轉換的 ObjectThe Object to convert.

傳回

Object,代表轉換過的值。An Object that represents the converted value.

例外狀況

無法執行轉換作業。The conversion cannot be performed.

備註

實作自訂型別作者想要的 XAML 支援類型轉換行為,通常TypeConverter支援的類別ConvertFrom從字串的行為。Custom type authors that intend to support a type conversion behavior for XAML typically implement a TypeConverter class that supports ConvertFrom behavior from a string. 此行為可讓從提供做為 XAML 屬性值的字串類型轉換,並提供 XAML 處理器,讓物件可以產生已剖析的物件圖形中,從字串中,建立物件所需的支援。This behavior enables type conversion from the string provided as a XAML attribute value and provides a XAML processor with the support needed to create an object from the string, so that the object can be produced in a parsed object graph. 自訂型別或成員的自訂型別由套用TypeConverterAttribute定義,具有屬性參考自訂TypeConverter實作。Custom types or members of custom types are indicated by applying TypeConverterAttribute to the definitions, with the attribute referencing the custom TypeConverter implementation.

基於 XAML 用途,您不通常提供分支實作根據cultureFor XAML purposes, you do not typically provide branching implementations based on culture. 這是因為在開發環境內容中,先行編譯的 XAML 是與執行階段的特定文化特性資訊 XAML 不相關的 XAML 類型轉換。This is because XAML is precompiled in a development environment context, and culture-specific information for runtime XAML is not relevant for XAML type conversion. 如需詳細資訊,請參閱 < XAML 概觀的型別轉換子For more information, see Type Converters for XAML Overview.

給繼承者的注意事項

請覆寫這個方法以提供您自己的轉換需求。Override this method to provide your own conversion requirements.

context 參數可以用於擷取環境的其他資訊,而這個轉換子就是從該環境叫用的。Use the context parameter to extract additional information about the environment from which this converter is invoked. 這個參數可以是null,所以一定要檢查。This parameter can be null, so always check it. 甚至,內容物件上的屬性可能會傳回 nullAlso, properties on the context object can return null.

用來支援 XAML 和自訂類型的型別轉換子的實作模式,請參閱XAML 概觀的型別轉換子For implementation patterns for type converters that are used to support XAML and custom types, see Type Converters for XAML Overview.

另請參閱

適用於