2012-02-15 10 views
1

リストボックスのitemtemplate内で選択されたイベントを変更する必要があります。私のリストボックスは、3つのテキストブロックと1つのイメージで構成されています。私は3番目のテキストブロックテキストだけを取得したい、3番目のテキストブロックを選択すると、テキストブロック内のテキストがポップアップとして表示されます。リストボックス内のitemtemplateのSelecteditemイベント

私はビジュアルツリーを使ってテキストブロックを検索しましたが、3番目のテキストブロックではなく最初のテキストブロックの値をとります。 2番目と3番目のテキストブロックの値を取得するにはどうすればよいですか。リストボックス内のテキストボックスをクリックしたときにのみ、ポップアップをトリガする必要があります。

<ListBox Name="listBox1" Width="Auto" SelectionChanged="Listbox1_SelectionChanged"> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <StackPanel> 
       <Image Height="165" HorizontalAlignment="Left" Margin="10,40,-400,0" VerticalAlignment="Top" Width="175" Source="{Binding thumb}"/> 
       <TextBlock Name="pagetext" TextWrapping="Wrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="195,-135,-200,0" Text="{Binding page}" Foreground="#FF170101" /> 
       <TextBlock Name="titletext" Width="1000" TextWrapping="NoWrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="195,-167,-200,0" Text="{Binding title}" Foreground="#FF170101" /> 
       <TextBlock Name="text" Width="1000" TextWrapping="NoWrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="195,-167,-200,0" Text="{Binding title}" Foreground="#FF170101" /> 
      </StackPanel> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

答えて

1

使用TextBlock_MouseLeftButtonUpまたはTextBlock_Tapこの中

private void TextBlock_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) 
    { 
     TextBlock t = (TextBlock)sender; 
     string s= t.Text; 
    } 

上記の文字列s DISPLYあなたがしたい場所(テキストブロックをクリックすると、これは上昇です)。

+0

おかげで、あなたは私に投票を忘れてしまった –

+0

...私のためにその作業罰金をpavan? – Pavan

+0

申し訳ありませんパヴァン私は投票に十分な評判を持っていません –

1

問題のTextBlockButtonにラップするか、またはHyperlinkを追加する必要があります。どちらもコマンドをサポートし、Clickイベントを持っています。 (あなたはTemplateだけの簡単なContentPresenterであることをオーバーライドすることができButton invisbleを作るために)

<Button> 
    <Button.Template> 
     <ControlTemplate TargetType="Button"><ContentPresenter/></ControlTemplate> 
    </Button.Template> 
    <TextBlock .../> 
</Button> 
<TextBlock> 
    <!-- In SL you probably need a Run inside the Hyperlink and it may not be bindable --> 
    <Hyperlink Text="{Binding title}" .../> 
</TextBlock> 
関連する問題