多维数据绑定?怎样做?
我试图创建一组网格并将它们添加到滚动视图中。
它应该是这样的: http://tinypic.com/r/256gpxf/7
“出发地”显示在“其他站点”应该是动态的。我知道如何使用数据绑定创建标题(“其他站点”),但我需要获取每个站点的出发时间。它就像某种数据绑定中的数据绑定。
这很难解释,但如果你看一下屏幕截图,我想你们可以明白我的意思:)
编辑:
公交车站的类别:
public class BusStop
{
public string Name { get; private set; }
public string ID { get; private set; }
public List<Depature> Depatures { get; private set; }
public BusStop(string name, string id)
{
Name = name;
ID = id;
Depatures = new List<Depature>();
}
}
出发类别:
public class Depature
{
public string Destination { get; private set; }
public int Next { get; private set; }
public int NextNext { get; private set; }
public Depature(string destination, int next, int nextNext)
{
Destination = destination;
Next = next;
NextNext = nextNext;
}
}
每个车站都有一组不同的出发地点它。这就是我试图在网格中填充的内容。每个站点一个网格。这是有 4 个出发点的“静态”示例 xaml:
<Grid Margin="0,0,0,12">
<Grid.RowDefinitions>
<RowDefinition Height="42" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="38" />
<ColumnDefinition Width="280" />
<ColumnDefinition Width="46" />
<ColumnDefinition Width="46" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.ColumnSpan="2" Grid.Column="0" FontSize="32" Text="Other Stop" Foreground="#FFE37306" />
<TextBlock VerticalAlignment="Bottom" Grid.Row="0" Grid.Column="2" FontSize="12" Text="avgår"/>
<TextBlock VerticalAlignment="Bottom" Grid.Row="0" Grid.Column="3" FontSize="12" Text="nästa"/>
<Grid Grid.Row="1" Style="{StaticResource VasttrafikGridLine}" Background="#0D4774">
<TextBlock Style="{StaticResource VasttrafikTextLine}" Text="80" />
</Grid>
<TextBlock Margin="6,0,12,0" Grid.Row="1" Grid.Column="1" Text="Nils Eriksson Term" />
<TextBlock HorizontalAlignment="Left" Grid.Row="1" Grid.Column="2" Width="20" Text="5" />
<TextBlock HorizontalAlignment="Left" Grid.Row="1" Grid.Column="3" Width="20" Text="15" />
<Grid Grid.Row="2" Style="{StaticResource VasttrafikGridLine}" Background="#0D4774">
<TextBlock Style="{StaticResource VasttrafikTextLine}" Text="80" />
</Grid>
<TextBlock Margin="6,0,12,0" Grid.Row="2" Grid.Column="1" Text="Nils Eriksson Term" />
<TextBlock HorizontalAlignment="Left" Grid.Row="2" Grid.Column="2" Width="20" Text="5" />
<TextBlock HorizontalAlignment="Left" Grid.Row="2" Grid.Column="3" Width="20" Text="15" />
<Grid Grid.Row="3" Style="{StaticResource VasttrafikGridLine}" Background="#0D4774">
<TextBlock Style="{StaticResource VasttrafikTextLine}" Text="80" />
</Grid>
<TextBlock Margin="6,0,12,0" Grid.Row="3" Grid.Column="1" Text="Nils Eriksson Term" />
<TextBlock HorizontalAlignment="Left" Grid.Row="3" Grid.Column="2" Width="20" Text="5" />
<TextBlock HorizontalAlignment="Left" Grid.Row="3" Grid.Column="3" Width="20" Text="15" />
<Grid Grid.Row="4" Style="{StaticResource VasttrafikGridLine}" Background="#0D4774">
<TextBlock Style="{StaticResource VasttrafikTextLine}" Text="80" />
</Grid>
<TextBlock Margin="6,0,12,0" Grid.Row="4" Grid.Column="1" Text="Nils Eriksson Term" />
<TextBlock HorizontalAlignment="Left" Grid.Row="4" Grid.Column="2" Width="20" Text="5" />
<TextBlock HorizontalAlignment="Left" Grid.Row="4" Grid.Column="3" Width="20" Text="15" />
</Grid>
使用网格是一个好主意吗?看来我必须用行定义等来定义每一行。
提前致谢!
/R
Im trying to create a set of grids and add them to a scrollview.
Here is what it should look like:
http://tinypic.com/r/256gpxf/7
The "depatures" showing up under "other stop" should be dynamic. I know how to create the titles ("other stop") using databinding but i need to get the depatures for each stop. It's like a databinding in a databinding of some kind.
It's hard to explain but if you look at the screenshot i think you guys can figure out what i mean :)
EDIT:
The class for busstops:
public class BusStop
{
public string Name { get; private set; }
public string ID { get; private set; }
public List<Depature> Depatures { get; private set; }
public BusStop(string name, string id)
{
Name = name;
ID = id;
Depatures = new List<Depature>();
}
}
Depature class:
public class Depature
{
public string Destination { get; private set; }
public int Next { get; private set; }
public int NextNext { get; private set; }
public Depature(string destination, int next, int nextNext)
{
Destination = destination;
Next = next;
NextNext = nextNext;
}
}
Each stop has a diffrent set of depatures attached to it. That's what im trying to populate in a grid. One grid for each stop. Here is "static" sample xaml for a stop with 4 depatures:
<Grid Margin="0,0,0,12">
<Grid.RowDefinitions>
<RowDefinition Height="42" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="38" />
<ColumnDefinition Width="280" />
<ColumnDefinition Width="46" />
<ColumnDefinition Width="46" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.ColumnSpan="2" Grid.Column="0" FontSize="32" Text="Other Stop" Foreground="#FFE37306" />
<TextBlock VerticalAlignment="Bottom" Grid.Row="0" Grid.Column="2" FontSize="12" Text="avgår"/>
<TextBlock VerticalAlignment="Bottom" Grid.Row="0" Grid.Column="3" FontSize="12" Text="nästa"/>
<Grid Grid.Row="1" Style="{StaticResource VasttrafikGridLine}" Background="#0D4774">
<TextBlock Style="{StaticResource VasttrafikTextLine}" Text="80" />
</Grid>
<TextBlock Margin="6,0,12,0" Grid.Row="1" Grid.Column="1" Text="Nils Eriksson Term" />
<TextBlock HorizontalAlignment="Left" Grid.Row="1" Grid.Column="2" Width="20" Text="5" />
<TextBlock HorizontalAlignment="Left" Grid.Row="1" Grid.Column="3" Width="20" Text="15" />
<Grid Grid.Row="2" Style="{StaticResource VasttrafikGridLine}" Background="#0D4774">
<TextBlock Style="{StaticResource VasttrafikTextLine}" Text="80" />
</Grid>
<TextBlock Margin="6,0,12,0" Grid.Row="2" Grid.Column="1" Text="Nils Eriksson Term" />
<TextBlock HorizontalAlignment="Left" Grid.Row="2" Grid.Column="2" Width="20" Text="5" />
<TextBlock HorizontalAlignment="Left" Grid.Row="2" Grid.Column="3" Width="20" Text="15" />
<Grid Grid.Row="3" Style="{StaticResource VasttrafikGridLine}" Background="#0D4774">
<TextBlock Style="{StaticResource VasttrafikTextLine}" Text="80" />
</Grid>
<TextBlock Margin="6,0,12,0" Grid.Row="3" Grid.Column="1" Text="Nils Eriksson Term" />
<TextBlock HorizontalAlignment="Left" Grid.Row="3" Grid.Column="2" Width="20" Text="5" />
<TextBlock HorizontalAlignment="Left" Grid.Row="3" Grid.Column="3" Width="20" Text="15" />
<Grid Grid.Row="4" Style="{StaticResource VasttrafikGridLine}" Background="#0D4774">
<TextBlock Style="{StaticResource VasttrafikTextLine}" Text="80" />
</Grid>
<TextBlock Margin="6,0,12,0" Grid.Row="4" Grid.Column="1" Text="Nils Eriksson Term" />
<TextBlock HorizontalAlignment="Left" Grid.Row="4" Grid.Column="2" Width="20" Text="5" />
<TextBlock HorizontalAlignment="Left" Grid.Row="4" Grid.Column="3" Width="20" Text="15" />
</Grid>
Is using a grid even a good idea? It seems like i have to define each row with rowdefinitions etc.
Thanks in advance!
/R
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:既然您发布了代码,我就调整了模板。顺便说一句,您拼错了“Departures”,缺少“r”。
我使用的示例数据:
一般方法应该是定义嵌套的 DataTemplates,这里我使用一个 ItemsControl,其
ItemTemplate
包含标题和另一个ItemsControl
:看起来像这样(当然它缺少您的特定样式和覆盖):
你仍然没有指定你的三个不同的块来自哪里等等。但除此之外的任何事情绝对是你的问题......
Edit: Now that you posted your code i adjusted the template. You misspelled "Departures" by the way, it's missing an "r".
Sample data i use:
The general approach should be to define nested
DataTemplates
, here i use aItemsControl
whoseItemTemplate
contains headers and anotherItemsControl
:Looks something like this (it's lacking your specific styles and overrides of course):
You still did not specify where your three different blocks come from etc. but anything beyond this is definitely your problem...