0

我已经DataTemplate为 WPF 编写了一个ListBox。但是当我使用 3 个中的 2 个特定图标时,布局会发生变化:

http://i.stack.imgur.com/xMp7F.png

那是我的ItemTemplate

<ListBox.ItemTemplate>
     <DataTemplate>
          <Grid>
              <Grid.ColumnDefinitions>
                   <ColumnDefinition Width="auto" />
                   <ColumnDefinition Width="auto" />
                   <ColumnDefinition Width="*" />
               </Grid.ColumnDefinitions>
                   <TextBlock Text="{Binding id}" Name="tbID" Margin="5" FontWeight="Bold" FontSize="12" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" />
                   <Image Height="25" Width="25" Source="{Binding img_src}" HorizontalAlignment="Center" Grid.Column="1" />
                   <StackPanel Margin="10, 0, 0, 0" Grid.Column="2" Orientation="Vertical" >
                       <TextBlock  FontWeight="Bold" FontSize="11" Text="{Binding errorOriginal}"/>
                       <TextBlock  FontSize="10" Text="{Binding errorGerman}" />
                       <!-- Margin="10, 0, 0, 0"   -->
                   </StackPanel>
         </Grid>
    </DataTemplate>
</ListBox.ItemTemplate>

这是我的课:

public class compEntry
{
    public int id { get; set; }
    public string img_src { get; set; }
    public string errorOriginal { get; set; }
    public string errorGerman { get; set; }
}

请告诉我我的错误。

//编辑:当我手动填写我的班级(没有字符串)时,它可以工作:

compList.Add(new compEntry() { id = i, img_src = img, errorOriginal = errText[i], errorGerman = trans }); // not working
compList.Add(new compEntry() { id = i, img_src = img, errorOriginal = "test", errorGerman = "test" });//working

//EDIT2:找到解决方案。只是修剪字符串:

 compList.Add(new compEntry() { id = i, img_src = img, errorOriginal = errText[i].Trim(), errorGerman = trans.Trim() }); 
4

1 回答 1

0

找到了解决方案。只是修剪字符串:

compList.Add(new compEntry() { id = i, img_src = img, errorOriginal = errText[i].Trim(), errorGerman = trans.Trim() });
于 2013-10-21T09:09:56.710 回答