Click here to Skip to main content
16,005,141 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm trying to make an aplication where I have a lot of link to differen web sites on a stackpanel, getting there content from a MainViewModel, so when I click on the description it opens the web via WebBrowserTask. However, I want to have the Uri on the MainViewModel and get that info in the .cs, which takes me to the site

My xaml code is

C#
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" Margin="0,0,0,17" Tap=Open_Web>
<Image Height="100" Width="100"   Margin="0,0,0,0" Source="{Binding ImgWeb}" HorizontalAlignment="Left"/>
                            <StackPanel Width="311">
                                <TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                                <TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
                            </StackPanel>
                         </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate> 
            </ListBox>

My .cs is

C#
private void Open_Web(object sender, RoutedEventArgs e)
    {
        WebBrowserTask webBrowserTask = new WebBrowserTask();
        webBrowserTask.Uri = new Uri("I DONT KNOW");
        webBrowserTask.Show(); 

And my MainViewModel code is:

C#
this.Items.Add(new ItemViewModel() { LineOne = "Web Name", LineTwo = "Web description", Uri = "http://WebSite.com" });


If I dont bind the info, It works, but I dont know how to get the Uri on
webBrowserTask.Uri = new Uri("I DONT KNOW");
form the MainViewModel
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900