We found a strange problem in the course of the project. When a class's property name is "name", the ListBox, DataGrid can not display it in the browser, either using DisplayMemberPath or using a DataTemplate.
the MainPage.xaml :
Code: Select all
<Page
x:Class="bugforname.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:bugforname"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<ListBox Width="300"
x:Name="listBox1"
DisplayMemberPath="name"
SelectedValuePath="id"
Background="yellow"
HorizontalAlignment="Left"
>
</ListBox>
</Grid>
</Page>
the MainPage.xaml.cs:
Code: Select all
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace bugforname
{
public partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
// Enter construction logic here...
this.Loaded += MainPage_Loaded;
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
List<TestBug> buglist = new List<bugforname.TestBug>()
{
new TestBug()
{
id=1, name="Text111"
},
new TestBug()
{
id=2, name="Text222"
},
new TestBug()
{
id=3, name="Text333"
},
};
listBox1.ItemsSource = buglist;
// throw new NotImplementedException();
}
}
public class TestBug
{
public int id
{
get;
set;
}
public string name
{
get;
set;
}
public string showname
{
get
{
return name;
}
}
}
}