Note that there are some explanatory texts on larger screens.

plurals
  1. POClick link on WP7 view model
    text
    copied!<p>Im building an app for Windows phone 7. I have a panorama page with a view model - a list of main menu items. I cant work out how to bind these clicks to data, or to create a link to other pages. (Ie; each of this meny items need to be lickable to link to another page).. What I tried is, assigned a click event to the text to {binding Link} in my main viewmodel.cs list of items. Each 'Link' item was a Event handler as per the code shown below in the cs file. This doesnt work so wondering how to achieve this. The example below of the xaml file shows all text links in the list go to the same Event: 'TextBlock_MouseLeftButtonDown_Wales'. but of course I want them to go to each there own pages.</p> <p>MainPage.xaml</p> <pre><code> &lt;ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}" Background="#75000000"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Horizontal" Margin="0,0,0,10"&gt; &lt;!--Replace rectangle with image--&gt; &lt;!-- &lt;Rectangle Height="100" Width="100" Fill="#FFE5001b" Margin="12,0,9,0"/&gt; --&gt; &lt;Image Source="/images/image1.png" Height="70" HorizontalAlignment="Left" Margin="0,0,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="77" Opacity="1" OpacityMask="#C8000000" /&gt; &lt;StackPanel Width="311"&gt; &lt;TextBlock Text="{Binding LineOne}" MouseLeftButtonDown="TextBlock_MouseLeftButtonDown_Wales" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/&gt; &lt;TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/&gt; &lt;/StackPanel&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>MainViewModel.cs</p> <pre><code> this.Items.Add(new ItemViewModel() { LineOne = "England", LineTwo = "blahblah", Link = "TextBlock_MouseLeftButtonDown_London" }); this.Items.Add(new ItemViewModel() { LineOne = "Scotland", LineTwo = "blahblah ", Link = "TextBlock_MouseLeftButtonDown_London" }); this.Items.Add(new ItemViewModel() { LineOne = "Wales", LineTwo = "blahblah ", Link = "TextBlock_MouseLeftButtonDown_Wales" }); this.Items.Add(new ItemViewModel() { LineOne = "London", LineTwo = "blablbah ", Link = "TextBlock_MouseLeftButtonDown_London" }); </code></pre> <p>I hope you understand what I am tring to do here, let me know if you need more info. Many thanks. Dan</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload