【发布时间】:2021-09-29 12:10:21
【问题描述】:
我是 WPF 的新手,为此花了数小时寻找解决方案,但我找不到任何东西。
我想用DataTemplate显示一个类的所有属性:
<ItemsControl ItemsSource="{Binding Car}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
public class Car
{
public int Axes { get; set; }
public int Seats { get; set; }
public int Doors { get; set; }
public VehicleProperties.Car.Type Type { get; set; }
public int MaxWeight { get; set; }
public Fuel Fuel { get; set; }
public double ConsumptionPer100km { get; set; }
public bool Childseat { get; set; }
public string Brand { get; set; }
public string Model { get; set; }
public int FirstRegistration { get; set; }
public int Mileage { get; set; }
public Transmission Transmission { get; set; }
public int Power { get; set; }
public bool Tempomat { get; set; }
public SolidColorBrush Color { get; set; }
public int PollutionClass { get; set; }
public int EnvironmentalBadge { get; set; }
}
如何至少显示名称并正确绑定ItemsSource 和TextBlock?我需要那个,因为在此之后,我将设计带有DataType 属性的DataTemplates。
【问题讨论】:
标签: c# wpf xaml data-binding