2011-09-15 46 views
1

コンボボックス内のアイテムリストに問題があります。彼らはitemsourceが再ロードされたときにコンボボックスが表示されない項目が表示される

(ファイルから)更新をいけないWPFは、次のようになります。

<DockPanel x:Name="Dock_Profil" DataContext="{Binding Profile, UpdateSourceTrigger=PropertyChanged,NotifyOnSourceUpdated= True}"> 
        <StackPanel DockPanel.Dock="Top" Orientation="Horizontal"> 
         <ComboBox Margin="5" Width="200" ItemsSource="{Binding}" DisplayMemberPath="ProfilName" IsSynchronizedWithCurrentItem="True" 
            x:Name="cmbProfil" SelectedIndex="0" ></ComboBox> 
         <Button Margin="5"> 
          <StackPanel Orientation="Horizontal" > 
           <Image Margin="2" Stretch="None" Source="/MEC_EDINeu;component/Resources/Add24.png" /> 
           <Label>Neues Profil</Label> 
          </StackPanel> 
         </Button> 
        </StackPanel> 

プロパティプロファイルがこのタイプである:私がする必要がある特定の時点で

Public Class EDIProfile 
    Inherits ObservableCollection(Of EDIProfil) 

プロファイルの内容を再ロードしてください。

と呼ばれています。私が使用してMainWindow.xaml.vbに後で確認するとき

(OnPropertyChangedをはViewModelBase.vbで実装され、MainWindowViewModelに渡される):

For Each item As EDIProfil In cmbProfil.Items 
      MsgBox(item.ProfilName & "__" & item.lastFA) 
     Next 

を正しい項目がでています。

GUIのコンボボックスにはまだ古いコンテンツが表示されます。


A回避策は、私が見つかりました。(しかし、私は、すべてのコンボボックスのためにそれを使用したくない): を(mainwindow.xaml.vbで)私はそのラインを使用する場合:

cmbProfil.Items.Refresh() 

の更新をコンボボックスの作業によって表示される項目(それへの結合をはずの?)


私はここにいくつかの助けを得ることを期待して、WPFにはかなり新しいです。事前に

おかげ


私はMainWindowViewModel内のデータをロードすると(正しい方法は、とにかくそれを行うことです?):

Public Sub loadProfile() 
     'Profile.Load() 
     Profile.Clear() 
     Dim xmls As XmlSerializer = New XmlSerializer(GetType(EDIProfile)) 
     Dim reader As New StreamReader(System.Reflection.Assembly.GetExecutingAssembly().Location.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().Location.LastIndexOf("\") + 1) & "EDIProfile.xml") 
     Dim temp As New EDIProfile 
     ' MsgBox("KK") 
     temp = xmls.Deserialize(reader) 
     For Each item As EDIProfil In temp 
      Profile.Add(item) 
     Next 
     reader.Close() 
     OnPropertyChanged("Profile") 

    End Sub 

それは

+0

アイテムをリロードする前にコンボボックスを開かないと正しく表示されます。 – BernhardAF

+0

ComboBoxを更新するのに、どんな種類のマルチスレッドを使用していますか? – Rachel

+0

@Rachelいいえわたしはいません – BernhardAF

答えて

0

はこれを試してみてください動作します。 DataContextバインディングを削除し、ItemsSourceを直接Profileにバインドします。

<DockPanel x:Name="Dock_Profil"> 
     <StackPanel DockPanel.Dock="Top" 
        Orientation="Horizontal"> 
      <ComboBox Margin="5" 
        Width="200" 
        ItemsSource="{Binding Profile, 
              UpdateSourceTrigger=PropertyChanged, 
              NotifyOnSourceUpdated= True}" ... /> 
+0

ありがとうございましたが、既にそれを試しました(そしてそれは動作を変更しませんでした)。また、datacontextはドックパネル内の他の要素にも使用されています。 – BernhardAF

関連する問題