locked
how to sort images in alist box

    Question

  • how to sort images in a listbox in metro style app
    Tuesday, July 17, 2012 12:36 PM

Answers

  • Hello,

     

    It depends on what order you want to sort for your images. You can follow these codes, and it sort by name.

     
       <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <ListView x:Name="listView1" HorizontalAlignment="Left" Height="326" Margin="299,70,0,0" VerticalAlignment="Top" Width="334"/>
    
        </Grid>

    #include <collection.h>
    #include <list>
    using namespace listimage;
    
    using namespace Platform;
    using namespace Platform::Collections;
    using namespace Windows::UI::Xaml::Media::Imaging;
    using namespace std;
    
    
    
    
    	// Create Map to streo images with name
    	Map<String^,Image^>^ imagemap=ref new Map<String^,Image^>();
    	
    	// Create list to sort names
    	list<String^> list_name;
    
    	// Add data into them
    	BitmapSource^ bitmap=ref new BitmapImage(ref new Uri("ms-appx:///Assets/Logo.png"));
    	Image Image1;
    	Image1.Source=bitmap;
    
    	// We can sort by name
    	imagemap->Insert("logo",%Image1);
    	list_name.push_back("logo");
    
    	// Add three 
    	bitmap=ref new BitmapImage(ref new Uri("ms-appx:///Assets/SmallLog.png"));
    	Image Image2;
    	Image2.Source=bitmap;
    
    	imagemap->Insert("SmallLog",%Image2);
    	list_name.push_back("SmallLog");
    
    	bitmap=ref new BitmapImage(ref new Uri("ms-appx:///Assets/StoreLogo.png"));
    	Image Image3;
    	Image3.Source=bitmap;
    
    	imagemap->Insert("StoreLogo",%Image3);
    	list_name.push_back("StoreLogo");
    
    	// Do this in sort function, first clear the front items.
    	listView1->Items->Clear();
    
    	// Sort by name
    	list_name.sort();
    
    	// Add image in a loop
    	list<String^>::iterator it;
    	for (it=list_name.begin(); it!=list_name.end(); it++)
    	{
    		listView1->Items->Append(imagemap->Lookup(*it));
    	}
    

     

    Best regards,

    Jesse



    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, July 18, 2012 6:39 AM

All replies

  • Hello,

     

    It depends on what order you want to sort for your images. You can follow these codes, and it sort by name.

     
       <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <ListView x:Name="listView1" HorizontalAlignment="Left" Height="326" Margin="299,70,0,0" VerticalAlignment="Top" Width="334"/>
    
        </Grid>

    #include <collection.h>
    #include <list>
    using namespace listimage;
    
    using namespace Platform;
    using namespace Platform::Collections;
    using namespace Windows::UI::Xaml::Media::Imaging;
    using namespace std;
    
    
    
    
    	// Create Map to streo images with name
    	Map<String^,Image^>^ imagemap=ref new Map<String^,Image^>();
    	
    	// Create list to sort names
    	list<String^> list_name;
    
    	// Add data into them
    	BitmapSource^ bitmap=ref new BitmapImage(ref new Uri("ms-appx:///Assets/Logo.png"));
    	Image Image1;
    	Image1.Source=bitmap;
    
    	// We can sort by name
    	imagemap->Insert("logo",%Image1);
    	list_name.push_back("logo");
    
    	// Add three 
    	bitmap=ref new BitmapImage(ref new Uri("ms-appx:///Assets/SmallLog.png"));
    	Image Image2;
    	Image2.Source=bitmap;
    
    	imagemap->Insert("SmallLog",%Image2);
    	list_name.push_back("SmallLog");
    
    	bitmap=ref new BitmapImage(ref new Uri("ms-appx:///Assets/StoreLogo.png"));
    	Image Image3;
    	Image3.Source=bitmap;
    
    	imagemap->Insert("StoreLogo",%Image3);
    	list_name.push_back("StoreLogo");
    
    	// Do this in sort function, first clear the front items.
    	listView1->Items->Clear();
    
    	// Sort by name
    	list_name.sort();
    
    	// Add image in a loop
    	list<String^>::iterator it;
    	for (it=list_name.begin(); it!=list_name.end(); it++)
    	{
    		listView1->Items->Append(imagemap->Lookup(*it));
    	}
    

     

    Best regards,

    Jesse



    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, July 18, 2012 6:39 AM
  • thankz .
    Wednesday, July 18, 2012 12:47 PM