Universal Windows App 获取选中项名称
Universal Windows App get slected item name
我有以下 xaml 代码:
<ListBox SelectionMode="Single" Name="MenuBox" SelectionChanged="MenuBox_SelectionChanged">
<ListBoxItem x:Name="test_item">
<StackPanel Orientation="Horizontal">
<TextBlock Padding="10 0 0 0" FontSize="20" Text="lalal" VerticalAlignment ="Center"/>
</StackPanel>
</ListBoxItem>
</ListBox>
现在我想获取所选项目的名称 (!),在本例中为 selection_changed 事件中的 "test_item"。
我试过了:
var item = MenuBox.SelectedItem.ToString();
这个字符串告诉我以下内容:"Windows.UI.Xaml.Controls.ListBoxItem"。
我需要 ListBoxItem 的名称来相应地更改场景。
您需要像这样获取 ListBoxItem 的名称 属性:
var item = ((ListBoxItem)MenuBox.SelectedItem).Name;
我有以下 xaml 代码:
<ListBox SelectionMode="Single" Name="MenuBox" SelectionChanged="MenuBox_SelectionChanged">
<ListBoxItem x:Name="test_item">
<StackPanel Orientation="Horizontal">
<TextBlock Padding="10 0 0 0" FontSize="20" Text="lalal" VerticalAlignment ="Center"/>
</StackPanel>
</ListBoxItem>
</ListBox>
现在我想获取所选项目的名称 (!),在本例中为 selection_changed 事件中的 "test_item"。
我试过了:
var item = MenuBox.SelectedItem.ToString();
这个字符串告诉我以下内容:"Windows.UI.Xaml.Controls.ListBoxItem"。 我需要 ListBoxItem 的名称来相应地更改场景。
您需要像这样获取 ListBoxItem 的名称 属性:
var item = ((ListBoxItem)MenuBox.SelectedItem).Name;