2011-06-30 7 views
0

は私持っているWPFでコンボボックスに関連する問題がWPFコンボボックスに割り当てるのSelectedItem

CertificatesListがCertificateEntryのリストがある

<ComboBox Name="CertificateComboBox" Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" Margin="1,59,0,48" IsEnabled="{Binding SecurityEnabled}" 
          ItemsSource="{Binding CertificatesList}" DisplayMemberPath="CertName" SelectedItem="{Binding Certificate, Mode=TwoWay}" ToolTip="List of SSL certificates. Select a value from the combobox."> 
</ComboBox> 

コンボボックスのための私のXAMLコードは

public class CertificateEntry 
{ 
    public string CertName { get; set; } 
    public string CertHash { get; set; } 
    public X509Certificate2 certificte {get; set; } 
    public CertificateEntry(X509Certificate2 cert) 
    { 
     certificte = cert; 
     if (cert.FriendlyName.Equals("")) 
     { 
      CertName = cert.Issuer; 
     } 
     else 
     { 
      CertName = cert.FriendlyName; 
     } 
     CertHash = cert.Thumbprint; 
    } 
    public string ToString() 
    { 
     return CertName; 
    } 
} 

プロパティのSelectedItemプロパティは、オブジェクトis

public CertificateEntry Certificate 
    { 
     get 
     {     
      return _certificate; 
     } 

     set 
     { 
      if (_certificate == value) 
       return; 

      _certificate = value; 
      OnPropertyChanged("Certificate"); 
     } 
    } 

私の問題は、私は_certificateは、上記の呼び出しがされた後CertificateEntryオブジェクト
そのは、追加の時計では値

を取っていないCertificateComboBox.SelectedItem

this.CertificateComboBox.SelectedItem = _certificate; 

にオブジェクトを割り当てるしようとしているときであります`私はassigneを表示したい

this.CertificateComboBox.SelectedItem = null 

割り当てが起きていない、 はnull d証明書をコンボボックスでデフォルトの選択値として使用していますが、これは起こっていません。

答えて

0

ItemsSource内にあるオブジェクトにのみ、選択したItemを設定できます。

よろしく ドミニク

0

私は混乱しています...あなたは、あなたのコンボの選択した項目のプロパティCertificateを作成しましたが、あなたはそのようにそのSelectedItemプロパティを割り当てる

this.CertificateComboBox.SelectedItem = _certificate; 

をおそらく_certicateがどこにありますかヌル。

私はあなただけでいくつかの値は、あなたの項目ソースに属している有効なCertificateEntryある

Certificate = some value 

を行う必要があると思います。

+0

_certicateはnullではない証明書オブジェクトです – Hari

+1

@Hari _certificateは、コンボのSelectedItemにバインドされた証明書プロパティに使用している変数の名前です。説明しようとすると、_cerficateを直接使用しないでください。単に証明書のプロパティを値、NOT _certificateで設定すると、正常に動作します。 – Dummy01

関連する問題