-1

我正在为以下问题寻找一个很好的代码解决方案。

我有一个要绑定到几个标签的列表。MyObject 类仅包含几个字段(字符串和整数)。此列表包含 3 个元素。在我看来,我希望有以下布局

  1. 元素 1
  2. 元素 2
  3. 元素 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"/>

做这个的最好方式是什么 ?我确信我可以用一些松散的代码来做到这一点,但我更喜欢一个简洁的解决方案。

非常感谢你 !!

4

1 回答 1

0
<ListView ItemsSource={Binding MyObjectsList}>
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding Number}" />
                <Label Content="{Binding Element}" />
            </StackPanel>
        </DataTempalte>
    </ListView.ItemTemplate>
</ListView>

Number 和 Element 是 MyObject 的属性。

于 2012-04-05T09:50:34.137 回答