• windows phone listbox的点击事件


    前台

    <ListBox x:Name="listbox1" Margin="6">
    <ListBox.ItemTemplate>
    <DataTemplate>
    <Grid Margin="15" Tag="{Binding ImageID}" Tap="Post_Click">
    <StackPanel Orientation="Horizontal">
    <Image Source="{Binding Image}" Width="150" Height="120" Stretch="Fill"/>
    <TextBlock Text="{Binding ImageName}" FontSize="30" TextWrapping="Wrap" Width="300"/>
    </StackPanel>
    </Grid>
    </DataTemplate>
    </ListBox.ItemTemplate>
    </ListBox>

     

    后台

    private T FindFirstElementInVisualTree<T>(DependencyObject parentElement) where T : DependencyObject
    {
    var count = VisualTreeHelper.GetChildrenCount(parentElement);
    if (count == 0)
    return null;
    for (int i = 0; i < count; i++)
    {
    var child = VisualTreeHelper.GetChild(parentElement, i);
    if (child != null && child is T)
    {
    return (T)child;
    }
    else
    {
    var result = FindFirstElementInVisualTree<T>(child);
    if (result != null)
    return result;
    }
    }
    return null;
    }

    需要绑定

    private void Post_Click(object sender, System.Windows.Input.GestureEventArgs e)
    {
    var selectedIndex = listbox1.SelectedIndex;
    ListBoxItem item = listbox1.ItemContainerGenerator.ContainerFromIndex(selectedIndex) as ListBoxItem;
    StackPanel border = FindFirstElementInVisualTree<StackPanel>(item);
    Image img = FindFirstElementInVisualTree<Image>(item);
    TextBlock txtBlock = FindFirstElementInVisualTree<TextBlock>(item);
    MessageBox.Show(txtBlock.Text.ToString());
    }
  • 相关阅读:
    MATLAB 粒子群优化PSO
    MATLAB 简单图像融合
    MATLAB 拉普拉斯残差金字塔
    MATLAB 随机抽样一致RANSAC
    MATLAB TV模型图像修复
    MATLAB radon变换
    MATLAB 二维直方图
    MATLAB 自适应中值滤波RAMF
    MATLAB 二值图像内外边界跟踪
    MATLAB 各向异性扩散)
  • 原文地址:https://www.cnblogs.com/ZXdeveloper/p/3583343.html
Copyright © 2020-2023  润新知