मेरे पास एक क्रमबद्ध सूचीबॉक्स है और प्रत्येक आइटम की पंक्ति संख्या प्रदर्शित करने की आवश्यकता है। इस डेमो में मेरे पास एक नाम वर्ग संपत्ति वाला व्यक्ति वर्ग है। सूची बॉक्स नाम से क्रमबद्ध व्यक्तियों की एक सूची प्रदर्शित करता है। मैं पंक्ति संख्या सूची सूची के डेटामैप्लेट में कैसे जोड़ सकता हूं ???क्रमांकित सूचीबॉक्स
XAML:
<Window x:Class="NumberedListBox.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<ListBox
ItemsSource="{Binding Path=PersonsListCollectionView}"
HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Window>
कोड के पीछे:
using System;
using System.Collections.ObjectModel;
using System.Windows.Data;
using System.Windows;
using System.ComponentModel;
namespace NumberedListBox
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
Persons = new ObservableCollection<Person>();
Persons.Add(new Person() { Name = "Sally"});
Persons.Add(new Person() { Name = "Bob" });
Persons.Add(new Person() { Name = "Joe" });
Persons.Add(new Person() { Name = "Mary" });
PersonsListCollectionView = new ListCollectionView(Persons);
PersonsListCollectionView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
DataContext = this;
}
public ObservableCollection<Person> Persons { get; private set; }
public ListCollectionView PersonsListCollectionView { get; private set; }
}
public class Person
{
public string Name { get; set; }
}
}
उह, क्या यह एन^2 व्यवहार में नतीजा नहीं है? स्क्रीन पर प्रत्येक आइटम के लिए, मौजूदा आइटम इंडेक्स की अनुक्रमणिका खोजने के लिए सभी संभावित वस्तुओं पर पुनरावृत्ति करें। – Armentage