0
我有兩個獨立的類即:數據綁定/填充在Windows手機在列表框中的項目
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訪問樓層類中的FName? 我做的是:
<TextBlock Text="{Binding Path=Floors.FName }" />
但它沒有工作。 :(
很抱歉的長期職位。
感謝這個...我現在明白如何綁定的作品! – xiriusly
謝謝,請投票,如果它幫助你:) –