0
我是WPF.I的新手,我想獲取與其UserList_SelectionChanged事件上選定的特定Listitem相對應的TextBlock控件的文本。WPF Listbox控件
<ListView Height="188" Canvas.Left="11" Canvas.Top="167" Width="252">
<ListBox Name="UserList" Width="224" BorderThickness="0" SelectionChanged="UserList_SelectionChanged_1">
<ListBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="Status-user-online-icon.png" Height="19" Width="18" />
<TextBlock FontSize="14" FontStretch="Expanded" Width="98">User1</TextBlock>
<Line Stroke="red" X1="0" Y1="25" X2="{Binding ElementName=root, Path=Width}" Y2="25" Opacity="0.22" />
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="Status-user-online-icon.png" Height="19" Width="18" />
<TextBlock FontSize="14" FontStretch="Expanded" Width="98">User2</TextBlock>
<Line Stroke="red" X1="0" Y1="25" X2="{Binding ElementName=root, Path=Width}" Y2="25" />
</StackPanel>
</ListBoxItem>
</ListBox>
</ListView>
任何幫助,將不勝感激。
爲什麼投lstView.SelectedItem到對象時,它已經類型對象?而不是ListBoxItem lbi = this.lstView.ItemContainerGenerator.ContainerFromItem(selectedEntry)作爲ListBoxItem;只是做:ListBoxItem lbi =(ListBoxItem)lstView.SelectedItem – rauland
正確在這種情況下鑄造不是必需的。 – Gun