wrappanel 및 listbox를 사용하여 wp7에 내 항목을 표시했습니다. 항목 클릭 이벤트가 작동하지 않습니다. 다음과 같이 내 코드는wrappanel 목록 상자 항목 선택 이벤트
<Grid x:Name="ContentPanel" Grid.Row="1" Height="Auto">
<ListBox x:Name="lstDevice">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate >
<StackPanel>
<Button x:Name="btnData" >
<StackPanel Orientation="Vertical">
<Canvas
Width="175"
Height="175"/>
<TextBlock Text="{Binding Name}" Width="175" />
</StackPanel>
</Button>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
위의 디자인 코드와 C# 코드가 번호 또는 선택된 항목을 인식하는 몇 가지 속성을 목록 상자 항목 선택 이벤트를 생성하고 활용하는 방법 아래
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
lstDevice.ItemsSource = MainPage.user.dArray.ToList();
lstDevice.SelectionChanged += item_Select;
}
private void item_Select(object sender, SelectionChangedEventArgs e)
{
int p = ((ListBox)sender).SelectedIndex;
}
이다? 미리 감사드립니다!
감사합니다! 친구! 작동합니다! – Kevan
이제는 내 dArray에 lstDevice.ItemSource에 대한 정보가 있습니다. OnButtonClick 메서드 dArray의 어느 요소를 클릭했는지 알고 싶습니다. 어떻게 할 생각인가? – Kevan
dArray 란 무엇입니까? 나는 람다 표현식을'var c = dArray.Where (x => x == nameInTag) .Select (x => x) .FirstOrDefault();' –