在WPF中,我可以使用Panel的Children集合作为ComboBox的ItemsSource:
WPF Panel's Children as ComboBox's ItemsSource
但在UWP中,这会抛出异常:"参数不正确。" &安培; vbCrLf
Code-XAML:
<StackPanel>
<StackPanel Name="Panel1">
<TextBox Text="Item 1" />
<TextBox Text="Item 2" Margin="0,10,0,0" />
</StackPanel>
<ComboBox Margin="0,10,0,0" Name="Combo1" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Text}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
守则背后:
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
Combo1.ItemsSource = Panel1.Children
End Sub
我如何在UWP实现同样的目标?