2012-03-13 71 views
0

我有兩個列表框,我都綁定到相同的選定索引。這樣做的原因是,在第一個我輸入一些東西,然後指定哪個屬性屬於:列表框選擇錯誤,當一個項目插入兩次

例如:

可以與

  • 何使用
  • 加德納
  • 客廳

一切正常時,每個項目occurres只有一次,但是當我有類似

  • 狗屋
  • 魚府

然後同步不起作用。 我試過IsSynchronizedWithCurrentItem="True",但是當我打開頁面時,這給了我一個例外。

這是列表框代碼

<ListBox BorderBrush="{x:Null}" Grid.Column="0" HorizontalAlignment="Stretch" 
     ItemsSource="{Binding Animals}" 
     SelectedItem="{Binding SelectedListBoxItem,Mode=TwoWay}" 
     SelectedIndex="{Binding SelectedIndex,Mode=TwoWay}" 
     ItemTemplate="{StaticResource ListBoxItemTemplate}"/> 
<ListBox BorderBrush="{x:Null}" Grid.Column="1" HorizontalAlignment="Stretch" 
     ItemsSource="{Binding Places}" 
     SelectedIndex="{Binding SelectedIndex,Mode=TwoWay}" 
     ItemTemplate="{StaticResource ListBoxItemTemplate}"/> 

只是爲了不引起有關的DataTemplate

<DataTemplate x:Key="ListBoxItemTemplate"> 
    <TextBlock Text="{Binding Name}" Height="15"/> 
</DataTemplate> 

編輯一些困惑: 當我想將它設置爲true我在設計師看以下消息

[Selector_IsSynchronizedWithCurrentItemCannotSetToTrue] Arguments: Debugging resource strings are unavailable. Often the key and arguments provide sufficient ....

兩個列表框中的項目數總是相同的。

異常(網頁錯誤)是通用

Line: 1 Error: Unhandled Error in Silverlight Application Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

+0

「但這給了我一個例外」 - 什麼異常?堆棧跟蹤? – 2012-03-13 14:48:21

+0

這兩個列表中的_number_個項目是否總是相等? – 2012-03-13 14:48:55

+0

@HenkHolterman是的......你首先在樹形視圖中添加一個「動物」,然後在另一個樹形視圖中添加一個「地點」。 – 2012-03-13 14:55:50

回答

0

而不是從我創建了一個新的選擇項,然後將其傳遞到列表框中的樹狀總是添加相同項目。這樣,你必須在不同的項目,但最後我只關心自己的ID(placeID),這樣也沒關係......

希望這可以幫助別人......

0

我也遇到同樣的問題在Windows Phone 7.1上。內部異常有點像:設置IsSynchronizedWithCurrentItem爲true不支持