2012-12-11 37 views
0

我目前正試圖設計一個表,聯繫信息,包括像電話,電子郵件或類似的符號圖標欄,我想從下一列中的文本對齊它們機器人會RelativeLayout的Windows Phone的

icon | Telephone: 
    | +1212354567 
icon | Email: 
    | [email protected] 

有沒有可以在功能上與Androids RelativeLayout進行比較的佈局?我試圖使用網格佈局,但這似乎是容易出錯和不夠準確。我不想將我的佈局分成列和行,而是我想描述它們在RelativeLayout(toLeft,toRight,AlignParentBottom等)中的位置。

StackPanel可以與LinearLayout進行比較,我想避免它,因爲它不適合我當前的設計。

Windows Phone和Android Layouts之間有任何比較,我可以定位? This one是不完整的,並不提供RelativeLayout的建議。

感謝您的幫助!

回答

2

我知道你說你不想使用網格,但我覺得你必須在這種情況下。

雖然我會將它與網格和堆棧面板結構化。

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition /> 
     <RowDefinition /> 
    </Grid.RowDefinitions> 

    <!-- Image for first row item --> 
    <Image Grid.Column="0" Grid.Row="0" Source="icon-url" /> 
    <!-- Container for the details of the first row item --> 
    <StackPanel Grid.Column="1" Grid.Row="0"> 
     <TextBlock Text="Telephone:" /> 
     <TextBlock Text="+1212354567" /> 
    </StackPanel> 

    <!-- Image for second row item --> 
    <Image Grid.Column="0" Grid.Row="1" Source="icon-url" /> 
    <!-- Container for the details of the second row item --> 
    <StackPanel Grid.Column="1" Grid.Row="1"> 
     <TextBlock Text="Email:" /> 
     <TextBlock Text="[email protected]" /> 
    </StackPanel> 

    <!-- Just add rows to the grid to continue the list --> 
</Grid> 
+0

是的,這是我現在最後的希望。我習慣於避免Android的嵌套佈局,因此我希望有一些類似於我曾經瞭解和喜歡的RelativeLayout的東西:)這樣我就可以只使用一個StackPanel,並且不必爲每個點添加一個新的StackPanel。 –

+1

這不是機器人。 StackPanel和Grid是XAML中最好的朋友。通常你將使用帶有DataTemplate的ItemsControl,所以你不必「爲每個點添加一個新的StackPanel」(框架會爲你做) – dotMorten

+0

我仍在研究數據綁定。我認爲它只適用於LongListSelector。我可以將Grid或StackPanel與相同的功能結合起來嗎? –

1

沒有面板比較,但冒險的人可以創建一個。有很多關於如何做到這一點的文章,但這裏有一個供參考。 http://www.switchonthecode.com/tutorials/wpf-tutorial-creating-a-custom-panel-control

也就是說,沒有理由不使用Grid來做你想做的事情。這不是「容易出錯」或「不夠準確」。不過,SharedSizeGroup應該成爲你的朋友。

+0

感謝您的回答。 SharedSizeGroup看起來很有前途。如果我想將一個單元格鏈接到另一個單元格,我只需要將所需的參數添加到該組中,並且它將定向到第一個單元格上? –

+0

SharedSizeGroup允許來自一個或多個網格的列或行共享相同的大小。例如,如果您爲使用網格的ListItems創建模板,則可能希望該網格中的列在每個列表項中具有相同的寬度。 http://bengribaudo.com/blog/2011/05/21/1228/wpf-separate-grids-auto-sized-columnsrows-with-synchronized-dimensions – wekempf

+0

感謝您的鏈接。但是,SharedSizeGroup僅適用於桌面上的WPF。正如標籤所示,我正在專門尋找Windows Phone解決方案。 –