Search code examples
c#windows-phone-8longlistselector

Windows phone 8.1 LongListSelector issue with button


I implemented LongListSelector controller instead of ListView contoller because I am using Windows Phone Silverlight Application.

I want to bind Name to the Button controller. But I am unable to complete it.

<Button  Name="{Binding Name}" Content="Download" Grid.Row="2" Grid.Column="1" Click="Button_Click_1" Width="170" Height="70" Background="#b3c833"></Button>

I succeed for TextBox and Image for LongListSelector controller.

Any advise would be greatly appreciated.

public class Station
{
    //  private string _stationName;

    private string _stationName;
    //  private BitmapImage bm = new BitmapImage(new Uri(@"Image/Darktheme.png", UriKind.RelativeOrAbsolute));
    private Uri bm;
    private string btnop;
    public Uri ImageUrl
    {
        get { return bm; }
        set { bm = value; }
    }

    public string Name
    {
        get { return _stationName; }
        set { _stationName = value; }
    }
    public string btnop1
    {
        get { return btnop; }
        set {
            btnop = value; }
    }
    public Station( Uri bm,string station, string ty)
    {
        this.Name = station;
    this.ImageUrl = bm;
        this.btnop1 = ty;
    }
}


ObservableCollection<Station> trainStations = new ObservableCollection<Station>();
trainStations.Add(new Station(new Uri("Assets/pdfdoc.png", UriKind.RelativeOrAbsolute),d, word));   

Solution

  • Use FrameworkElement.Tag property, according to MSDN.

    FrameworkElement.Tag gets or sets an arbitrary object value that can be used to store custom information about this element.

    This page states clearly. Binding can be done only to DependencyProperty. It cannot work on x:Name.

    If you want to iterate through the LongListSelector, you can bind the Name member to Tag property.