绑定超链接按钮

时间:2014-01-17 19:39:05

标签: windows-phone-8 hyperlink html-agility-pack

我正在尝试使用超链接的链接

<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!

1 个答案:

答案 0 :(得分:0)

我没有看到足够的代码可以肯定地说,但你必须有一些东西可以改变'link'属性。这意味着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));
        }
    }
}