0

I have a listbox in which I pass 5 items in each row. Xml file:

<ListBox x:Name="DatabaseBox">
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </Style>
    </ListBox.ItemContainerStyle>
        <ListBox.ItemTemplate>
    <DataTemplate>
            <DockPanel">
                <Image x:Name="ToggleFavoriteImage" Width="15" Height="15" Tag="{Binding Tag}" Source="{Binding ImageSource}" MouseLeftButtonDown="ToggleFavoriteImage_MouseLeftButtonDown"/>
                <TextBlock x:Name="ListBoxSName" Width="220" Text="{Binding Name}" Margin="30,0,0,0" FontSize="11" MouseLeftButtonDown="ListBoxSName_MouseLeftButtonDown"/>
                <Button x:Name="ListBoxSCoyntry" Height="17" Content="{Binding City}" FontSize="11" Click="ListBoxSCity_Click"/>
                <Button x:Name="ListBoxSCity"  Height="17" Content="{Binding Genre}" FontSize="11" Click="ListBoxSGenre_Click"/>
                <Button x:Name="ListBoxSGenre" Height="17" Content="{Binding Country}" FontSize="11" Click="ListBoxSCountry_Click"/>
            </DockPanel>
    </DataTemplate>
</ListBox.ItemTemplate>
    
</ListBox>

What I want to do is have Image and TextBlock docked Left, and all the others Docked right side by side. I tried DockPanel.Dock ="Rigth" for all the Buttons but things get very messed up.

Anyone with an idea?

4

2 回答 2

4

将每个视觉组包装在堆栈面板中并将停靠应用到堆栈面板,如下所示:

<DockPanel>
    <StackPanel DockPanel.Dock="Left">
         <Image x:Name="ToggleFavoriteImage" Width="15" Height="15" Tag="{Binding Tag}" Source="{Binding ImageSource}" MouseLeftButtonDown="ToggleFavoriteImage_MouseLeftButtonDown"/>
         <TextBlock x:Name="ListBoxSName" Width="220" Text="{Binding Name}" Margin="30,0,0,0" FontSize="11" MouseLeftButtonDown="ListBoxSName_MouseLeftButtonDown"/>
    </StackPanel>
    <StackPanel DockPanel.Dock="Right">
         <Button x:Name="ListBoxSCoyntry" Height="17" Content="{Binding City}" FontSize="11" Click="ListBoxSCity_Click"/>
         <Button x:Name="ListBoxSCity"  Height="17" Content="{Binding Genre}" FontSize="11" Click="ListBoxSGenre_Click"/>
         <Button x:Name="ListBoxSGenre" Height="17" Content="{Binding Country}" FontSize="11" Click="ListBoxSCountry_Click"/>
    </StackPanel>
</DockPanel>
于 2013-07-10T15:22:23.497 回答
0

使用Grid,DockPanel不是一个很好的控制。还有size-sharingGrids ,这对于项目控制通常很有用。

于 2013-07-10T15:23:07.993 回答