1

我正在尝试制作一个列表框,我可以在其中完全控制列表框中每个项目的外观。

我可以使项目水平拉伸。但是,所选项目的左侧有一条蓝色的细条。(图中,中间项被选中)。

我可以让这个蓝色条带消失吗?

替代文字 http://img44.imageshack.us/img44/949/boundlistboxdisplay.jpg

这是完整的代码。

<Window x:Class="SimpleListTemplate.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     >
    <Window.Resources>
        <XmlDataProvider x:Key="DcCharacters">
            <x:XData>
                <Characters xmlns="">
                    <Character HeroName="Catwoman" Identity="Selina Kyle" />
                    <Character HeroName="Batman" Identity="Bruce Wayne" />
                    <Character HeroName="Starman" Identity="Jack Knight" />
                </Characters>
            </x:XData>
        </XmlDataProvider>
    </Window.Resources>
    <Grid>
        <ListBox 
             ItemsSource="{Binding Source={StaticResource DcCharacters}, XPath=//Characters/*}" 
             HorizontalContentAlignment="Stretch">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Label 
                        Content="{Binding XPath=@HeroName}" 
                        Height="40" 
                        VerticalContentAlignment="Center"
                        Background="LightGreen"
                        BorderThickness="2"
                        BorderBrush="DarkGreen"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>
4

1 回答 1

1

这是您的代码的更新。

<Window x:Class="SimpleListTemplate.Window1"     
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 <Window.Resources>
    <XmlDataProvider x:Key="DcCharacters">
        <x:XData>
            <Characters xmlns="">
                <Character HeroName="Catwoman" Identity="Selina Kyle" />
                <Character HeroName="Batman" Identity="Bruce Wayne" />
                <Character HeroName="Starman" Identity="Jack Knight" />
            </Characters>
        </x:XData>
    </XmlDataProvider>
    <Style TargetType="{x:Type ListBoxItem}" x:Key="ContainerStyle">
        <Setter Property="Padding" Value="0,0,0,0"/>
    </Style>
</Window.Resources>
<Grid>
    <ListBox 
        ItemsSource="{Binding Source={StaticResource DcCharacters}, XPath=//Characters/*}"
        ItemContainerStyle="{StaticResource ContainerStyle}" 
        HorizontalContentAlignment="Stretch">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Label 
                    Content="{Binding XPath=@HeroName}"
                    Height="40"
                    VerticalContentAlignment="Center"
                    Background="LightGreen"
                    BorderThickness="2"
                    BorderBrush="DarkGreen"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>
</Window>

这可能会解决您的问题。

于 2009-09-11T09:27:36.000 回答