Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Need help for displaying numbers on images in WPF

i have a button and a listbox on my WPF window, when i click on button all the images should display in the listbox.up to here it is fine and working my code:

XAML code for listbox:
<pre lang="xml"><ListBox
            Name="Frameslistbox"
            SelectionChanged="Frameslistbox_SelectionChanged"
            Grid.Column="0"
            Grid.Row="0"
            HorizontalAlignment="Left"
            VerticalAlignment="Bottom"
            Margin="8,0,0,8"
            Width="150"
            Height="146.5">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel
                        Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel
                        Orientation="Horizontal">
                        
                        <Image
                            Source="{Binding}"
                            Height="100"></Image>

                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>



List <bitmapimage> myimages=new List<bitmapimage>();
        //@".\\Output" here images are there
	DirectoryInfo myimagesdir=new DirectoryInfo(@".\\Output");
	foreach(FileInfo myimagesfile in myimagesdir.GetFiles("*.jpg"))
			{
				
			Uri imguri=new Uri(myimagesfile.FullName );
			myimages .Add(new BitmapImage(imguri));			    
			    	
			}			
			
		    Frameslistbox.ItemsSource =myimages;</bitmapimage></bitmapimage>


now in the list box for each image i want to display numbers in the listbox above image like if i have 10 images(images may change every time), i want 1,2,3---10 on respective images.

i have tried textblock but not got any thing

plz help how to bind numbers to images .

Thanks,
Posted

1 solution

Add the number you want to the stackpanel. Replace your list of Uris with a list of an object that includes the uri and a number, or bind to the selected index.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900