我正在尝试将项目添加到列表视图中,其中每个项目都有两个文本块,但由于某种原因,项目没有显示。这是我的XAML代码。
<Window x:Class="testapp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="524" Width="856">
<Grid Background="Black">
<!--<Image Height="44" HorizontalAlignment="Left" Margin="284,0,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="229" Source="/testapp;component/Images/Picture1.png" />-->
<Grid Height="431" HorizontalAlignment="Left" Margin="0,55,0,0" Name="grid1" VerticalAlignment="Top" Width="266" Background="Black" Opacity="0">
<ListView Height="430" HorizontalAlignment="Left" Margin="3,1,0,0" x:Name="listView1" VerticalAlignment="Top" Width="260" >
<ListView.ItemTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock Text="{Binding Name}" Foreground="Green" />
<TextBlock Text="{Binding Source}" Foreground="Green" />
</WrapPanel>
</DataTemplate>
</ListView.ItemTemplate>
<!-- <ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>-->
</ListView>
</Grid>
</Grid>
</Window>
这是我的C#代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace testapp
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
List<MyItems> items = new List<MyItems>();
items.Add(new MyItems() { Name = "House Party", Source = " DLNA" });
items.Add(new MyItems() { Name = "Outdoor Party", Source = " DLNA" });
listView1.ItemsSource = items;
}
}
public class MyItems
{
public String Name { get; set; }
public String Source { get; set; }
}
}
即使我将文本块绑定到名称和来源,它仍然没有显示。任何人都可以帮助我吗?提前谢谢。
答案 0 :(得分:0)
由于不透明度参数而未显示。你已经定义了
Opacity="0"
你的xaml 中的
请在(0-1)
之间的范围内进行旧代码
<Grid Height="431" HorizontalAlignment="Left" Margin="0,55,0,0" Name="grid1" VerticalAlignment="Top" Width="266" Background="Black" Opacity="0">
更改为(新密码)
<Grid Height="431" HorizontalAlignment="Left" Margin="0,55,0,0" Name="grid1" VerticalAlignment="Top" Width="266" Background="Black">