간단한 데이터베이스 (.sdf)를 콤보 박스에 바인딩하는 방법을 배우려고합니다. 내 테이블에 데이터 세트를 만들었습니다. 그런 다음 DataSource의 테이블을 내 컨트롤로 드래그했습니다. 빌드 경고/오류가 없으며 실행될 때 ComboBox가 비어 있습니다.XAML에서 WPF ComboBox 바인딩 - 왜 비어 있습니까?
<UserControl x:Class="OurFamilyFinances.TabItems.TransactionTab"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="414" d:DesignWidth="578" xmlns:my="clr-namespace:OurFamilyFinances" Loaded="UserControl_Loaded_1">
<UserControl.Resources>
<my:FinancesDataDataSet x:Key="financesDataDataSet" />
<CollectionViewSource x:Key="accountViewSource" Source="{Binding Path=Account, Source={StaticResource financesDataDataSet}}" />
</UserControl.Resources>
<Grid>
<ComboBox DisplayMemberPath="Name" Height="23" HorizontalAlignment="Left" ItemsSource="{Binding Source={StaticResource accountViewSource}}" Margin="3,141,0,0" Name="accountComboBox" SelectedValuePath="ID" VerticalAlignment="Top" Width="120">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
</Grid>
방송이 정확하다 경로는 selectedPath는 "ID"이고 displaypath은 "명칭"이다.
this.accountComboBox.ItemsSource = from o in db.Account
select new { o.ID, o.Name };
을하지만 XAML에서이 작업을 수행하는 방법을 배우고 싶습니다 내가 LINQ to SQL은이 작업을 수행하는 경우, 콤보 상자를 채우는 않습니다. DataGrid를 DataSource에서 드래그했지만 데이터가 채워지지 않았습니다. 어떤 생각?
감사합니다. 내가 해결책을 당신에게로 바꿀거야 :) – mdiehl13