使用Silverlight构建插件式应用程序(四)
2008-10-23 11:43:48 来源:WEB开发网界面文件如下:
<Grid x:Name="LayoutRoot" Background="Transparent">
<StackPanel HorizontalAlignment="Center">
<Image x:Name="nodeImg" />
<TextBlock x:Name="nodeText" Text="FriendName" FontSize="12" ></TextBlock>
</StackPanel>
</Grid>
下面从数据库获取数据形成图形:
1. 建立两个对象,保存节点的个数和节点之间的连线:
Dictionary<string, UserNode> userNodes = new Dictionary<string, UserNode>();
Dictionary<string, UserLine> userLines = new Dictionary<string, UserLine>();
2. 使用WCF从数据库获取数据,获取指定用户的人际关系数据:
WSMainClient ws = new WSMainClient(new System.ServiceModel.BasicHttpBinding(), new System.ServiceModel.EndpointAddress(serviceUri));
ws.GetFriendsCompleted += new EventHandler<GetFriendsCompletedEventArgs>(ws_GetFriendsCompleted);
ws.GetFriendsAsync("song");
3. 根据数据构建人际关系图形:
//添加用户节点,
foreach (UserRelaInfo ri in userRelaInfo)
{
string[] nodeLocal = ri.LocalStyle.Split(',');
CreateUserNode(ri, new Point(Convert.ToInt32(nodeLocal[0]), Convert.ToInt32(nodeLocal[1])));
}
//选择所有的用户组信息
var colltions = from uri in userRelaInfo where uri.RelaType == "colltion" orderby uri.RelationId select uri;
foreach (UserRelaInfo ri in colltions)
{
//添加用户和组之间的连线
CreateUserLine(ri.RelationId.ToString(), "song", ri.FriendName);
//添加每个组和朋友之间的连线
var userCollection = from uc in userRelaInfo where uc.Relation == ri.FriendName orderby uc.RelationId select uc;
foreach (UserRelaInfo tmpri in userCollection)
{
//添加用户和组之间的连线
CreateUserLine(tmpri.RelationId.ToString(), ri.FriendName, tmpri.FriendName);
}
}
Tags:使用 Silverlight 构建
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接