构建程序时,我无法从列表中看到数据。
这是XAML代码:
<ListView Name="alkoholCjenik" ItemsSource="items" ScrollViewer.HorizontalScrollBarVisibility="Hidden" Background="#FF4AC1A7" BorderBrush="{x:Null}" Foreground="#FF042271" FontFamily="Sitka Small">
<ListView.View>
<GridView>
<!-- declare a GridViewColumn for each property -->
</GridView>
</ListView.View>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListViewItem_PreviewMouseLeftButtonDown" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
这是C#代码:
public AlkoholnaPica()
{
InitializeComponent();
List<CjenikAlkohol> items = new List<CjenikAlkohol>();
items.Add(new CjenikAlkohol() { Drink = "Karlovacko", Price = 1 });
items.Add(new CjenikAlkohol() { Drink = "Ozujsko", Price = 2 });
items.Add(new CjenikAlkohol() { Drink = "Paulaner", Price = 3 });
alkoholCjenik.ItemsSource = items;
}
public class CjenikAlkohol
{
public string Drink { get; set; }
public int Price { get; set; }
}
private void ListViewItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var item = sender as ListViewItem;
if (item != null && item.IsSelected)
{
Application.Current.Shutdown();
}
}
我认为我的问题在于XAML代码。如何解决这个问题?
谢谢和亲切的问候