locked
Filtering a list of hyperlinks

    Question

  • I'm trying to build my first app for Windows 8. I have a long list of hyperlinks that I would like to let the user to sort by the first letter of the value in Content="{Binding LineOne}".  I'm pretty flexible on what would be the best way to do this - just something simple.  Can anyone point me in the right direction?  Thanks

    <StackPanel Width="400" Margin="8,-7,0,0" Height="Auto">
     <HyperlinkButton Content="{Binding LineOne}" TargetName="_blank" HorizontalAlignment="Left" Style="{StaticResource HyperlinkButtonStyle}"
      Margin="0,0,0,0" x:Name="hyp1" VerticalAlignment="Top" FontSize="{StaticResource PhoneFontSizeLarge}"
     NavigateUri="{Binding PondUrl}" />
     <TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="10,-2,10,0" Style="{StaticResource PhoneTextSubtleStyle}" />
     <TextBlock Text="{Binding LineThree}" TextWrapping="Wrap" Margin="10,-2,10,0" Style="{StaticResource PhoneTextSubtleStyle}" />
    </StackPanel>

    Saturday, April 4, 2015 6:55 PM

Answers

  • Saturday, April 4, 2015 8:45 PM
  • Hi ericvanburen,

    >>I would like to let the user to sort by the first letter of the value in Content="{Binding LineOne}".  

    For example you have defined the following class for data binding:

     public class test
        {
            public string LineOne { get; set; }
            public Uri PondUrl { get; set; }
            public string LineTwo { get; set; }
    public string LineThree { get; set; } }
    And use the following code for data binding to a ListBox:
    List<test> testlist;
    MyListBox.ItemsSource = testlist;
    Then if you want to sort by the first letter of the value in Content="{Binding LineOne}", please use the List OrderBy method as following:
     MyListBox.ItemsSource = null;
     List<test> MyList = testlist.OrderBy<test, string>(Item => Item.LineOne.Substring(0)).ToList();
     MyListBox.ItemsSource = MyList;

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, April 8, 2015 8:27 AM
    Moderator

All replies

  • Saturday, April 4, 2015 8:45 PM
  • Hi ericvanburen,

    >>I would like to let the user to sort by the first letter of the value in Content="{Binding LineOne}".  

    For example you have defined the following class for data binding:

     public class test
        {
            public string LineOne { get; set; }
            public Uri PondUrl { get; set; }
            public string LineTwo { get; set; }
    public string LineThree { get; set; } }
    And use the following code for data binding to a ListBox:
    List<test> testlist;
    MyListBox.ItemsSource = testlist;
    Then if you want to sort by the first letter of the value in Content="{Binding LineOne}", please use the List OrderBy method as following:
     MyListBox.ItemsSource = null;
     List<test> MyList = testlist.OrderBy<test, string>(Item => Item.LineOne.Substring(0)).ToList();
     MyListBox.ItemsSource = MyList;

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, April 8, 2015 8:27 AM
    Moderator