2014-01-17 131 views
0

我試圖到Bing的超鏈接的鏈接結合超鏈接按鈕

<HyperlinkButton NavigateUri="{Binding link}" /> 

我也有

public string link { get; set; } 

一類我的代碼背後,是

protected async override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     if (DeviceNetworkInformation.IsNetworkAvailable) 
     { 
      base.OnNavigatedTo(e); 
      string bass = ""; 
      using (var client = new HttpClient()) 
      { 
       bass = await client.GetStringAsync("http://www.itisbarsanti.it/orario/"); 
      } 
      HtmlDocument orari = new HtmlDocument(); 
      orari.LoadHtml(bass); 

      List<listaorari> classi = new List<listaorari>(); 

      listaorari classe00 = new listaorari(); 
      classe00.Titolo = orari.DocumentNode.SelectSingleNode("//a[@href='Classi/Classe0.html']").InnerText.Trim(); 
      classe00.link = "http://www.itisbarsanti.it/orario/Classi/Classe0.html"; 
      classi.Add(classe00); 

      listaorari classe01 = new listaorari(); 
      classe01.Titolo = orari.DocumentNode.SelectSingleNode("//a[@href='Classi/Classe1.html']").InnerText.Trim(); ; 
      classe01.link = "http://www.itisbarsanti.it/orario/Classi/Classe1.html"; 
      classi.Add(classe01); 

      lista_orari.ItemsSource = classi; 
     } 
     else 
     { 
      List<listaorari> orario0 = new List<listaorari>(); 
      listaorari orario = new listaorari(); 
      orario.Titolo = "No internet!"; 
      orario.link = ""; 
      orario0.Add(orario); 
      lista_orari.ItemsSource = orario0; 
     } 

當我部署應用程序時,我沒有看到超鏈接按鈕,但我可以按下它們,當我按下應用程序崩潰時!

HELPPPPPP!

回答

0

我沒有看到足夠的代碼可以肯定地說,但是你必須有一些東西冒起來對「鏈接」屬性進行修改。這意味着ViewModel或綁定屬性保留的任何位置需要實現INotifyPropertyChanged(或類似),並在屬性被修改(= set)時引發屬性已更改的事件。

該應用可能會崩潰,因爲未設置NavigateUrl屬性。

該代碼將是這個樣子:

// Create a class that implements INotifyPropertyChanged. 
public class MyLinkVM: INotifyPropertyChanged 
{ 
    private string _link; 

    // Declare the PropertyChanged event. 
    public event PropertyChangedEventHandler PropertyChanged; 

    // Create the property that will be the source of the binding. 
    public string Link 
    { 
     get { return _link; } 
     set 
     { 
      _link = value; 
      // Call NotifyPropertyChanged when the source property 
      // is updated. 
      NotifyPropertyChanged("Link"); 
     } 
    } 


    // NotifyPropertyChanged will raise the PropertyChanged event, 
    // passing the source property that is being updated. 
    public void NotifyPropertyChanged(string propertyName) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, 
       new PropertyChangedEventArgs(propertyName)); 
     } 
    } 
} 
+0

我已經解決了對不起 – Quakenxt