ValueType プロパティは、Value プロパティによって返される値および予想される値のタイプを指定します。たとえば、ValueType を Decimal に設定すると、Value プロパティは小数値を返します。ユーザー入力は、Value プロパティから戻る前に 10 進数に変換されます。Text プロパティは一方で、値のテキスト表現を常に返します。
注: Value プロパティの設定は Text プロパティも更新します。
注: ユーザーが ValueEditor のコンテンツを入力/変更すると、Text および Value プロパティは現在のコンテンツを反映するために同時に更新されます。ユーザー入力が関連付けられた ValueType に解析できない場合、Text プロパティは更新されますが、Value プロパティは最後に解析された値を保持します。その場合、IsValueValid プロパティは False を返し、ユーザー入力が無効であることを示します。
Private Sub Button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Me.textEditor1.ValueType = GetType(Decimal) Me.textEditor1.Format = "C" Me.textEditor1.FormatProvider = New System.Globalization.CultureInfo("fr-FR") ' Even though we are setting the Value property to 10.5 as a float, the ' editor will automatically convert the value to type set on ValueType ' property which we set to Decimal above. Me.textEditor1.Value = CType(10.5, System.Single) ' The Value property will automatically convert and return values of type ' set on the ValueType property, which we set above to Decimal. Debug.WriteLine("Value = " & Me.textEditor1.Value.ToString() & " as " & Me.textEditor1.Value.GetType().Name) ' Text property will return text representation of value without any formatting ' applied to it. This is what's going to be displayed when the editor enters ' edit mode. Debug.WriteLine("Text = " & Me.textEditor1.Text) ' DisplayText property will return text representation of value with formatting ' applied to it. Debug.WriteLine("DisplayText = " & Me.textEditor1.DisplayText) End Sub
public void button1_Click( object sender, RoutedEventArgs e ) { this.textEditor1.ValueType = typeof( Decimal ); this.textEditor1.Format = "C"; this.textEditor1.FormatProvider = new System.Globalization.CultureInfo( "fr-FR" ); // Even though we are setting the Value property to 10.5 as a float, the // editor will automatically convert the value to type set on ValueType // property which we set to Decimal above. this.textEditor1.Value = (float)10.5; // The Value property will automatically convert and return values of type // set on the ValueType property, which we set above to Decimal. Debug.WriteLine( "Value = " + this.textEditor1.Value.ToString( ) + " as " + this.textEditor1.Value.GetType( ).Name ); // Text property will return text representation of value without any formatting // applied to it. This is what's going to be displayed when the editor enters // edit mode. Debug.WriteLine( "Text = " + this.textEditor1.Text ); // DisplayText property will return text representation of value with formatting // applied to it. Debug.WriteLine( "DisplayText = " + this.textEditor1.DisplayText ); }