2012-03-22 6 views

答えて

2

ください....私を助けることができるしてくださいエラーメッセージが表示されましたポストあなたの例外に関する詳細。 また、PasswordChar入力財産と標準PasswordBoxを使用して検討してください。

<PasswordBox PasswordChar="#"/> 

UPDATE:あなたのPromptCharプロパティに

使用このchar型のコンバータ:

public class CharTypeConverter : TypeConverter 
    { 
     public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) 
     { 
      if (sourceType == typeof(string)) 
       return true; 
      return base.CanConvertFrom(context, sourceType); 
     } 

     public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) 
     { 
      if (destinationType == typeof(string)) 
       return true; 
      return base.CanConvertTo(context, destinationType); 
     } 

     public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) 
     { 
      if (value == null) 
       return '_'; 

      if (value is string) 
      { 
       string s = (string)value; 
       if (s.Length == 0 || s.Length > 1) 
        return '_'; 
       return s[0]; 
      } 

      return base.ConvertFrom(context, culture, value); 
     } 

     public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) 
     { 
      if (value != null && !(value is char)) 
       throw new ArgumentException("Invalid prompt character", "value"); 

      if (destinationType == typeof(string)) 
      { 
       if (value == null) 
        return String.Empty; 
       char promptChar = (char)value; 
       return promptChar.ToString(); 
      } 
      return base.ConvertTo(context, culture, value, destinationType); 
     } 
    } 

使用法:

[TypeConverter(typeof(CharTypeConverter))] 
public char PromptChar 
{ 
    get { ... } 
    set { ... } 
} 
+0

お返事をありがとうございます。私はPasswordBoxを使いませんでした。私はTextBoxの基本クラスを使ってカスタムMaskTextBoxを作成しています。 ** char型の** PromptChar **という1つの依存プロパティがあります。もし私がを与えるならば。その後、実行中に上記のエラーが表示される – Ponmalar

+0

デバッグしましたか?どのような種類の値が依存関係プロパティに送られますか? MaskedTextBoxクラスの関連する実装も投稿してください。 –

+0

はい、「#」として値を取得するだけです。次のような特性を有する。 public char PromptChar { get {return(char)GetValue(PromptCharProperty); } set {SetValue(PromptCharProperty、value);} } } // PromptCharのバッキングストアとしてDependencyPropertyを使用する。これにより、アニメーション、スタイリング、バインディングなどが可能になります。 public static readonly PromptCharProperty = DependencyProperty.Register( "PromptChar"、typeof(char)、typeof(MaskEditTextBox)、新しいPropertyMetadata( '_'、OnPromptCharChanged)); OnPromptCharChangedイベントの – Ponmalar

関連する問題