به نام خدا سلام بر برنامه نویسان عزیز 😉 در این مطلب کد قرار دادن آیتمها درون ListBox به صورت غیرهمزمان (Asynchronous) با wpf و سی شارپ #C را آماده کردم. انشاالله که این آموزش برای شما مفید باشد.
تصاویر خروجی نهایی این کد:
کد قرار دادن آیتمها درون ListBox به صورت غیرهمزمان (Asynchronous) با wpf و سی شارپ #C :
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF" Height="200" Width="300"
Loaded="Window_Loaded">
<Window.Resources>
<DataTemplate x:Key="ListItemTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding}" VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<StackPanel>
<ListBox x:Name="listBox" ItemTemplate= "{StaticResource ListItemTemplate}"/>
</StackPanel>
</Window>
//File:Window.xaml.cs
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Threading;
namespace WpfApplication1
{
public partial class Window1 : Window
{
private ObservableCollection<string> numberDescriptions;
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
numberDescriptions = new ObservableCollection<string>();
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF" Height="200" Width="300"
Loaded="Window_Loaded">
<Window.Resources>
<DataTemplate x:Key="ListItemTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding}" VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<StackPanel>
<ListBox x:Name="listBox" ItemTemplate= "{StaticResource ListItemTemplate}"/>
</StackPanel>
</Window>
//File:Window.xaml.cs
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Threading;
namespace WpfApplication1
{
public partial class Window1 : Window
{
private ObservableCollection<string> numberDescriptions;
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
numberDescriptions = new ObservableCollection<string>();