単純なデータベース(.sdf)をコンボボックスにバインドする方法を学習しようとしています。テーブルを含むデータセットを作成しました。次に、テーブルをデータソースからコントロールにドラッグしました。ビルドの警告/エラーはなく、実行すると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は「Name」です。Linq to Sqlでこれを行うと、コンボボックスにデータが入力されます。
this.accountComboBox.ItemsSource = from o in db.Account
select new { o.ID, o.Name };
しかし、XAMLでこれを行う方法を学びたいと思います。データソースからもデータグリッドをドラッグしましたが、どちらも入力されていません。何か案が?