Click here to Skip to main content
15,434,532 members
Home / Discussions / WPF
   

WPF

 
QuestionBind Grid Row's IsExpanded To Row's Data Object Pin
Kevin Marois31-Mar-14 12:41
professionalKevin Marois31-Mar-14 12:41 
QuestionUser Control Question Pin
Kevin Marois25-Mar-14 8:05
professionalKevin Marois25-Mar-14 8:05 
AnswerRe: User Control Question Pin
_Maxxx_2-Apr-14 18:39
professional_Maxxx_2-Apr-14 18:39 
GeneralRe: User Control Question Pin
Kevin Marois2-Apr-14 18:49
professionalKevin Marois2-Apr-14 18:49 
GeneralRe: User Control Question Pin
_Maxxx_2-Apr-14 19:36
professional_Maxxx_2-Apr-14 19:36 
GeneralRe: User Control Question Pin
Kevin Marois3-Apr-14 5:47
professionalKevin Marois3-Apr-14 5:47 
GeneralRe: User Control Question Pin
BubingaMan23-Apr-14 4:13
MemberBubingaMan23-Apr-14 4:13 
QuestionPrefixing ListBoxItem index in DataTemplate Pin
Dominick Marciano22-Mar-14 21:33
professionalDominick Marciano22-Mar-14 21:33 
I have a class called Steps and one of the properties is called Text (but it has several others as well). When a user types text in a text box (called txtText) and click the button (called btnAddEntry), and new Steps class is created and added to the list box.

My issue is how to format the entries in the list box. I would like the list box to show the value of the Text property of the Step just added, but I would also like the index of the item just added to be prefixed to the text.

The XAML for me list box is:
XML
<ListBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Name="lstSteps" Margin="5">
           <ListBox.ItemTemplate>
               <DataTemplate>
                   <Label Content="{Binding Path=Text}" />
               </DataTemplate>
           </ListBox.ItemTemplate>
       </ListBox>


So if I type the entries "First Item", "Second Item", "Third Item" into txtText and click the btnAddEntry the list box will show
VB
First Item
Second Item
Third Item

However I want the list box to show:
VB
1. First Item
2. Second Item
3. Third Item

I've attempted this by modifying the ListBox.ItemTemplate in various ways, but just can't seem to figure it out. I have tried things like the following:
XML
<ListBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Name="lstSteps" Margin="5">
           <ListBox.ItemTemplate>
               <DataTemplate>
                   <Label Content="{Binding Path=Index}" />
                   <Label Content="{Binding Path=Text}" />
               </DataTemplate>
           </ListBox.ItemTemplate>
       </ListBox>

As well as using RelativeSource to Self, but I can never get the list box item to prefix it's index within the list box.

I really want this down in XAML because there are buttons to move items up and down the list box after they are added (so the user can reorder items instead of deleting them and re-entering them) and if I using bindings in the item template, these numbers should auto-update.

Any help with this will is greatly appreciated. Thanks in advance for any help.
A black hole is where God tried to divide by zero.

There are 10 kinds of people in the world; those who understand binary and those who don't.

AnswerRe: Prefixing ListBoxItem index in DataTemplate Pin
SledgeHammer0123-Mar-14 9:22
MemberSledgeHammer0123-Mar-14 9:22 
GeneralRe: Prefixing ListBoxItem index in DataTemplate Pin
Dominick Marciano25-Mar-14 4:42
professionalDominick Marciano25-Mar-14 4:42 
GeneralRe: Prefixing ListBoxItem index in DataTemplate Pin
SledgeHammer0125-Mar-14 4:55
MemberSledgeHammer0125-Mar-14 4:55 
QuestionCustom Window WPF con Vb.Net Pin
Pablo Roberto Cuellar Ribera21-Mar-14 9:59
MemberPablo Roberto Cuellar Ribera21-Mar-14 9:59 
AnswerRe: Custom Window WPF con Vb.Net Pin
Kenneth Haugland21-Mar-14 10:11
mvaKenneth Haugland21-Mar-14 10:11 
GeneralRe: Custom Window WPF con Vb.Net Pin
Pablo Roberto Cuellar Ribera21-Mar-14 10:40
MemberPablo Roberto Cuellar Ribera21-Mar-14 10:40 
QuestionRe: Custom Window WPF con Vb.Net Pin
Kenneth Haugland23-Mar-14 10:49
mvaKenneth Haugland23-Mar-14 10:49 
AnswerRe: Custom Window WPF con Vb.Net Pin
Meshack Musundi24-Mar-14 20:04
professionalMeshack Musundi24-Mar-14 20:04 
GeneralRe: Custom Window WPF con Vb.Net Pin
Pablo Roberto Cuellar Ribera28-Mar-14 5:58
MemberPablo Roberto Cuellar Ribera28-Mar-14 5:58 
QuestionWPF problem with ScrollViewer Pin
Federico Barbieri20-Mar-14 23:48
MemberFederico Barbieri20-Mar-14 23:48 
AnswerRe: WPF problem with ScrollViewer Pin
Pete O'Hanlon21-Mar-14 0:08
mvaPete O'Hanlon21-Mar-14 0:08 
QuestionMoving Items Between StackPanels With Animation Pin
Saeid Mirzaee19-Mar-14 4:01
MemberSaeid Mirzaee19-Mar-14 4:01 
QuestionStyle In Resource Dictionary Not Found Pin
Kevin Marois17-Mar-14 16:49
professionalKevin Marois17-Mar-14 16:49 
AnswerRe: Style In Resource Dictionary Not Found Pin
Pete O'Hanlon18-Mar-14 5:45
mvaPete O'Hanlon18-Mar-14 5:45 
GeneralRe: Style In Resource Dictionary Not Found Pin
Kevin Marois18-Mar-14 5:46
professionalKevin Marois18-Mar-14 5:46 
QuestionWPF Data Grid - Bind Checkbox To Command On VM Pin
Kevin Marois17-Mar-14 8:13
professionalKevin Marois17-Mar-14 8:13 
AnswerRe: Treeview Textbox Focus Pin
Wayne Gaylard17-Mar-14 5:56
professionalWayne Gaylard17-Mar-14 5:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.