我是.Net開發人員,也是WP7開發人員的新手。我想要做的是構建我的界面,具體取決於我有多少物品一個列表。我的項目是agences與名稱,地址,2個電話號碼和一個圖像。WP7從列表(.x)構建用戶界面(.xaml)
在我的cs文件:
Agence agence1 = new Agence();
agence1.Name = "Name1";
agence1.Adress = " Adress1";
agence1.Telephone = "Tel1";
agence1.Telephone2 = "Tel01";
agence1.Region = "Region1";
agence1.Source=newBitmapImage(newUri(@"/App/Images/call.jpg",UriKind.Relative));
listAgences.Add(agence1);
在每個通訊社我的XAML文件:
<Grid x:Name="Agence1" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="280"/>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0">
<TextBlock Height="30" HorizontalAlignment="Center" Name="textBlock1" Text="{Binding listAgences[0].Nom}" VerticalAlignment="Top" FontSize="18" Foreground="Black" FontWeight="Bold" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1">
<TextBlock Height="30" HorizontalAlignment="Center" Name="textBlock5" Text="..." VerticalAlignment="Top" FontSize="15" Foreground="Black" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0">
<TextBlock Height="30" HorizontalAlignment="Center" Name="textBlock2" Text="Adresse" VerticalAlignment="Top" FontSize="18" Foreground="Black" />
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="0">
<TextBlock Height="30" HorizontalAlignment="Center" Name="textBlock3" Text="Téléphone :" VerticalAlignment="Top" FontSize="18" Foreground="Black" />
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="1">
<TextBlock Height="50" HorizontalAlignment="Center" Name="textBlock6" Text="..." VerticalAlignment="Bottom" FontSize="15" Foreground="Black" Width="279" Padding="10,15,0,0"/>
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="2" Height="50" VerticalAlignment="Bottom" Margin="0">
<Image Height="30" Name="image1" HorizontalAlignment="Center" Source="/App;component/Images/call.png" Margin="0,10,0,0" />
</StackPanel>
<StackPanel Grid.Row="4" Grid.Column="0">
<TextBlock Height="30" HorizontalAlignment="Center" Name="textBlock4" Text="Telephone 2 :" VerticalAlignment="Top" FontSize="18" Foreground="Black" />
</StackPanel>
<StackPanel Grid.Row="3" Grid.Column="1">
<TextBlock Height="50" HorizontalAlignment="Center" Name="textBlock7" Text="..." VerticalAlignment="Bottom" FontSize="15" Foreground="Black" Width="279" Padding="10,15,0,0"/>
</StackPanel>
</Grid>
現在我有4個AGENCES硬編碼添加到我的清單。所以在我的xaml文件中,我有四倍於xaml的編碼。很快我會消費一個web服務來獲得agences。我要的是隻有一次上面的代碼,做這樣的事情:
在MVC模式,我會爲一個菜單類似的東西在我的aspx頁面做:
<ul>
<% foreach (var agence in listAgences) { %> <li><%: agence.Name %></li> <% } %>
... building the UI
</ul>
我不我想在我的手機應用程序菜單只是一個簡單的例證。我不知道如何在WPF/XAML做。我可以在xaml文件中做到這一點,或者我必須在.cs文件中構建接口,如:this.add(Grid); this.Add(StackPanel中); ...
Thx爲您提供幫助。
我發現 可以做這項工作。不過,我仍然無法獲得語法結構。 –
wallou
2010-11-03 10:11:43