그래서 마침내 WinForms에서 WPF로 이동하기로 결정했습니다. 흥미로운 여행을하고 있습니다. 나는 ObservableCollection
을 ListBox
에 묶는 간단한 어플리케이션을 가지고있다.WPF의 컬렉션에 바인딩
namespace MyTestApp
{
public class Animal
{
public string animalName;
public string species;
public Animal()
{
}
public string AnimalName { get { return animalName; } set { animalName = value; } }
public string Species { get { return species; } set { species = value; } }
}
}
과 AnimalList
기업 :
Animal
기업이
namespace MyTestApp
{
public class AnimalList : ObservableCollection<Animal>
{
public AnimalList() : base()
{
}
}
}
을 그리고 마지막으로 여기 내 메인 창입니다 :
<Window x:Class="MyTestApp.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyTestApp"
Title="Window3" Height="478" Width="563">
<Window.Resources>
<local:AnimalList x:Key="animalList">
<local:Animal AnimalName="Dog" Species="Dog"/>
<local:Animal AnimalName="Wolf" Species="Dog"/>
<local:Animal AnimalName="Cat" Species="Cat"/>
</local:AnimalList>
</Window.Resources>
<Grid>
<StackPanel Orientation="Vertical" Margin="10,0,0,0">
<TextBlock FontWeight="ExtraBold">List of Animals</TextBlock>
<ListBox ItemsSource="{Binding Source={StaticResource animalList}, Path=AnimalName}"></ListBox>
</StackPanel>
</Grid>
이제 응용 프로그램을 실행하면 목록 상자에 "Dog", "Wolf"및 "Cat"대신 "D", "o"및 "g"가 채워집니다.
어딘가에 어리석은 짓을하고 있다는 강한 느낌이 들지만 (AnimalList 생성자일까요?)하지만 그게 뭔지 알 수는 없습니다. 어떤 도움을 주셔서 감사합니다.
빙고. 그것은 트릭을했다. – PoweredByOrange