0
사용자 지정 클래스 Contact
이 있습니다.콤보 상자에 사용자 지정 개체 데이터를 바인딩하는 방법
List<Contact>
을 ComboBox에 바인딩하려고합니다.
하지만 Windows.Resources
부분에 대한 올바른 구문/명령을 가져올 수 없습니다. 예 : 아래의 코드는 "형식 참조가 'List'라는 공용 유형을 찾을 수 없습니다.이 코드가 작동하려면 Windows.Resources
에 수정해야합니까?
XAML : 클래스 뒤에
<Window x:Class="dpwpf.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:dpwpf">
<Window.Resources>
<ObjectDataProvider
x:Key="contacts"
MethodName="GetContacts"
ObjectType="{x:Type system:List}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:GetContacts"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<StackPanel>
<StackPanel>
<TextBlock Text="Select the contact:"/>
<ComboBox ItemsSource="{Binding
Source={StaticResource contacts}}"/>
</StackPanel>
</StackPanel>
</Window>
코드 :
namespace dpwpf
{
class StoreDB
{
private string connectionString = "App_Data/main.sqlite";
public List<Contact> GetContacts()
{
SQLiteConnection conn = new SQLiteConnection("Data Source=" + connectionString);
SQLiteCommand cmd = conn.CreateCommand();
List<Contact> contacts = new List<Contact>();
try
{
conn.Open();
cmd.CommandText = String.Format("SELECT * FROM contacts");
SQLiteDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Contact contact = new Contact(
Int32.Parse(reader[0].ToString()),
reader[1].ToString(),
reader[2].ToString()
);
contacts.Add(contact);
}
}
finally
{
conn.Close();
}
return contacts;
}
}
}
귀하의 문제가이 라인에