Tap gesture as select, for listbox

人走茶凉 提交于 2019-12-25 06:47:18

问题


How do i create an event for it to detect that the user tapped on the item in listbox

<!--Pivot Control-->
<controls:Pivot Title="MY APPLICATION">
    <!--Pivot item one-->
    <controls:PivotItem Header="item1">
        <ListBox x:Name="lbFiles" HorizontalContentAlignment="Stretch" ItemTemplate="{StaticResource DataTemplate1}">
        </ListBox>
    </controls:PivotItem>
    <!--Pivot item two-->
    <controls:PivotItem Header="item2">
    </controls:PivotItem>
</controls:Pivot>

Code behind

 private void lbFile_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            selected = lbFiles.SelectedItem.ToString();
            general item = new general();
            item.viewimage(selected);
            NavigationService.Navigate(new Uri("/View.xaml", UriKind.Relative));
        }

headache THanks! :D


回答1:


You're not attaching the SelectionChanged event. You have a function for it there, but you're not making anything use it.

<ListBox x:Name="lbFiles" HorizontalContentAlignment="Stretch" SelectionChanged="lbfile_SelectionChanged" ItemTemplate="{StaticResource DataTemplate1}">
        </ListBox>

You need to attach events so that they are used. You should go through the first few WP7 tutorials on create.msdn - you'll find a lot of what you need to get started and feel more comfortable about things like this.



来源:https://stackoverflow.com/questions/9053420/tap-gesture-as-select-for-listbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!