我正在爲以下問題尋找一個很好的代碼解決方案。如何將列表的元素綁定到標籤
我有一個列表,我想綁定到一對標籤。 MyObject類只包含幾個字段(字符串和整數)。該列表包含3個元素。在我看來,我想有以下佈局
- 元1
- 元2
- 元3
哪裏 「元件1」, 「元素2」 和 「元素3」是MyObject類的一個屬性。
注意,視圖在Blend已經定義如下(我不想改變視圖代碼,但如果我沒有選擇...;)):
<Label Content="1." RenderTransformOrigin="0,0.404" Foreground="Black" FontSize="16" VerticalContentAlignment="Bottom" HorizontalContentAlignment="Right" FontFamily="Segoe UI Semibold"/>
<Label Content="2." RenderTransformOrigin="0,0.404" Foreground="Black" FontSize="16" VerticalContentAlignment="Bottom" HorizontalContentAlignment="Right" Grid.Row="1" FontFamily="Segoe UI Semibold"/>
<Label Content="3." Margin="0,0,0,1.077" RenderTransformOrigin="0,0.404" Foreground="Black" FontSize="16" VerticalContentAlignment="Bottom" HorizontalContentAlignment="Right" Grid.Row="2" FontFamily="Segoe UI Semibold"/>
<Label Content="Login bug startup (6 days)" Foreground="Black" FontSize="14.667" VerticalContentAlignment="Bottom" Grid.Column="1"/>
<Label Content="Setup screen exception (4 days)" Foreground="Black" FontSize="14.667" VerticalContentAlignment="Bottom" Grid.Column="1" Grid.Row="1"/>
<Label Content="No users available bug (1 day)" Foreground="Black" FontSize="14.667" VerticalContentAlignment="Bottom" Grid.Column="1" Grid.Row="2"/>
什麼是最好的如何做到這一點?我確信我可以用一些鬆散的代碼來做到這一點,但我更喜歡一個簡潔的解決方案。
非常感謝!
我可以爲列表中的每個元素創建一些屬性,但我確定這不是要走的路。我正在尋找一個完美的解決方案。 – 2012-04-05 09:40:45