C# 如何在SelectionChangeEvent从列表框中获取文本块中的文本?

C# 如何在SelectionChangeEvent从列表框中获取文本块中的文本?,c#,wpf,xaml,windows-phone-8,listbox,C#,Wpf,Xaml,Windows Phone 8,Listbox,在从我的列表框中选择项目期间,我试图从我的文本块中获取文本 这是我在xaml文件中为listbox编写的代码 <ListBox x:Name="listBox" Height="535" Margin="7,0,12,0" SelectionChanged="selectedItem" ItemsSource="{Binding}"> <ListBox.ItemsPanel> <ItemsPanelTemplat

在从我的列表框中选择项目期间,我试图从我的文本块中获取文本

这是我在xaml文件中为listbox编写的代码

<ListBox x:Name="listBox" Height="535" Margin="7,0,12,0" 
      SelectionChanged="selectedItem" 
      ItemsSource="{Binding}">

    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <toolkit:WrapPanel FlowDirection="LeftToRight" 
                ItemWidth="215" ItemHeight="215" />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>

    <ListBox.ItemTemplate x:Uid="info">
        <DataTemplate>
            <StackPanel>
                <Border>
                    <Image HorizontalAlignment="Left" Margin="6,6,0,0" 
                        Name="image1" Stretch="Fill" 
                        VerticalAlignment="Top" 
                        Source="{Binding imageSource}" />
                </Border>
                <TextBlock x:Name="path" Foreground="Transparent" 
                    Text="{Binding imagePath}"/>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>

</ListBox>

我非常感谢您的帮助。

如果它是从文本块发送的,它将是您的发件人。。。所以你可以做一些像

var text = ((TextBlock)sender).Text;
否则,您必须引用它绑定到的属性…

为什么,哦,为什么你要命名你的文本块
路径
??这会把每个人都搞糊涂的。。。称它为
TextBlockPath
,这样它就不会因为一个路径而模棱两可了

如果imagePath是类的属性,请尝试以下操作

var item = listBox.SelectedItem as className; // like ShareMediaTask

var task = new ShareMediaTask();
task.FilePath = item.imagePath;
task.Show();

是的,sir imagePath是一个类的属性。非常感谢,先生!现在它工作了!
var item = listBox.SelectedItem as className; // like ShareMediaTask

var task = new ShareMediaTask();
task.FilePath = item.imagePath;
task.Show();