【发布时间】:2014-04-29 18:52:14
【问题描述】:
我有一个带有 6 个列表框的窗口,我正在尝试制作一个小型汽车数据库,但我在第二个列表框中的绑定存在问题。当我尝试单击第一个列表框中的制造商时,绑定不起作用。
<Window x:Class="Autolab.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="500" Width="700"
Loaded="Window_Loaded_1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="119*" />
<ColumnDefinition Width="116*" />
<ColumnDefinition Width="137*" />
<ColumnDefinition Width="137*" />
<ColumnDefinition Width="134*" />
<ColumnDefinition Width="134*" />
</Grid.ColumnDefinitions>
<ListBox x:Name="hersteller" Grid.Column="0" DisplayMemberPath="h_name" SelectedValuePath="h_id"/>
<ListBox x:Name="marke" Grid.Column="1"
ItemsSource="{Binding SelectedItem.marken, ElementName=hersteller}" />
<ListBox x:Name="kraftstoff" Grid.Column="2" />
<ListBox x:Name="art" Grid.Column="3" />
<ListBox x:Name="werkstatt" Grid.Column="4" />
</Grid>
这是我的收藏
public partial class herstellers
{
public herstellers()
{
this.marken = new HashSet<marke>();
}
public int h_id { get; set; }
public string h_name { get; set; }
public virtual ICollection<marke> marken { get; set; }
}
}
【问题讨论】:
-
您能否展示您的模型
marke具有属性marken -
具有属性标记的模型?我没有将它作为属性外观我发布了我的模型
-
好吧,我认为如果你用
MVVM做你的事情会容易得多。您不想将来将您的Model绑定到View。 -
你把东西放在哪里了?
-
这就是我的信息在标记表中的要点
标签: c# wpf collections binding listbox