1
這不工作對我來說:綁定到UserControl元素的ListBox?
<StackPanel>
<ListBox x:Name="MyListBox"
ItemsSource="{StaticResource UserControlsCollection}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
<UserControl
Content="{Binding ElementName=MyListBox, Path=SelectedValue}"
/>
</StackPanel>
我得到這個在運行時「項目不在預期範圍內」的錯誤。這些數據:
<toolkit:ObjectCollection x:Key="UserControlsCollection">
<UserControl Style="{StaticResource UserControlListItemStyle}">
<Button>One Button</Button>
</UserControl>
<UserControl Style="{StaticResource UserControlListItemStyle}">
<ComboBox>
<ComboBoxItem Content="One" IsSelected="True" />
<ComboBoxItem Content="Two" />
<ComboBoxItem Content="Three" />
</ComboBox>
</UserControl>
<UserControl Style="{StaticResource UserControlListItemStyle}">
<Rectangle
Fill="Red"
Width="120" Height="120"
/>
</UserControl>
</toolkit:ObjectCollection>
我用Silverlight 4和4月份的Silverlight Toolkit測試了它,它工作正常。但是,我沒有你的風格「UserControlListItemStyle」。你使用的是什麼版本,你的風格是什麼樣的? – 2012-04-05 08:12:15
編輯最後評論:選擇一個項目時發生錯誤。在那種情況下,我也會遇到錯誤。我會更多地考慮它。 – 2012-04-05 08:21:13