我有两个单独的课程,即:
public class Floor {
private string fname;
public Floor(string name)
{
fname = name;
}
public int FName
{
set { fname = value; }
get { return fname; }
}
}
public class Building
{
List<Floor> floors;
string _bName;
public Building(string bname)
{
_bName = bname;
floors = new List<Floors>();
for(int i = 0; i < 3; i++)
{
floors.Add(new Floor("floor" + (i + 1)));
}
}
public string BName
{
set{ _bName = value; }
get{ return _bName; }
}
public List<Floor> Floors
{
set { floors = value; }
get { return floors; }
}
}
在我的 XAML (MainPage.xaml) 中:
<ListBox x:Name="lstBuilding" Background="White" Foreground="Black">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="10,0,0,15">
<StackPanel>
<TextBlock Text="{Binding Path=BName }" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
在我的 XAML.cs (MainPage.xaml.cs)
ObservableCollection< Building > buildings = new ObservableCollection< Building>();
for(int i = 0; i < 2; i++)
{
buildings.Add(new Building("building" + (i + 1)));
}
lstBuilding.ItemsSource = buildings
这是问题:
如何使用 XAML 访问 Floor 类中的 FName?我所做的是:
<TextBlock Text="{Binding Path=Floors.FName }" />
但它没有用。:(
对不起,很长的帖子。