我正在创建WP 8.1 Silverlight应用程序。
我有一个ObservableCollection字符串名称,它被设置到的ItemsSource的ListBox。中的按钮名称是哪些ListBox。然后,我想从中提取按钮ListBox,但是返回值为type string。
xaml代码是:
<ListBox x:Name="Game_ScrollViewer_online" Margin="41,104,128,6" SelectedValuePath="Current_game_button">
<ListBox.ItemTemplate>
<DataTemplate>
<Button x:Name="Current_game_button" Content="{Binding}"
HorizontalAlignment="Center" Height="80" Margin="-14,6,-15,0"
VerticalAlignment="Top" Width="210" Template="{StaticResource Button_CurrentLayout1}"
RenderTransformOrigin="0.5,0.5" Foreground="#FFCBECCB" FontFamily="Times New Roman"
Click="LoadGame_online" FontSize="16">
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
然后,我想提取button元素:
for (int i = 0; i < Game_ScrollViewer_online.Items.Count; i++)
{
var tempType = Game_ScrollViewer_online.Items[i].GetType();
Button tempBut = (Game_ScrollViewer_online.Items[i] as Button);
//Do stuff with button
}
但是正如所说的,返回类型是字符串。
为什么不是按钮?有没有办法访问按钮?
肥皂起泡泡
相关分类