问题描述:

I have a listbox that's binded to data, each item that's in the listbox i would like to have rounded corners. I've used a border tag, but it doesn't seem to be having any effect.

Here's the code i'm using;

<ListBox Name="lstbMenu" Margin="0,190,6,6" Height="488">

<ListBox.ItemTemplate>

<DataTemplate>

<Border CornerRadius="10">

<StackPanel Orientation="Horizontal" Margin="10" Background="Beige" Width="488">

<StackPanel Orientation="Vertical">

<Image Source="Images/1_0_1_1B59_7DA_2_11A0000_0_0_0.png" VerticalAlignment="Center" Height="80" Width="80" Margin="10"/>

</StackPanel>

<TextBlock Text="{Binding Path=menuText}" VerticalAlignment="Center" Margin="10" FontSize="20" />

<TextBlock Text="{Binding Path=menuPage}" Visibility="Collapsed" />

</StackPanel>

</Border>

</DataTemplate>

</ListBox.ItemTemplate>

</ListBox>

Does anyone have any idea's?

Thanks

网友答案:

By default a Border has a transparent background and a border thickness of 0. You need to set the Background, BorderBrush and BorderThickness properties of the Border.

网友答案:

This is your code bellow with the border's thickness set to 4 and the brush set to white, by setting the background property you can select a color or add an image as well:

<ListBox Name="lstbMenu" Margin="0,190,6,6" Height="488">

                <ListBox.ItemTemplate>

                    <DataTemplate>
                    <Border BorderThickness="4" BorderBrush="White" CornerRadius="10">
                        <StackPanel Orientation="Horizontal" Margin="10" Background="Beige" Width="488">
                            <StackPanel Orientation="Vertical">
                                <Image Source="Images/1_0_1_1B59_7DA_2_11A0000_0_0_0.png" VerticalAlignment="Center" Height="80" Width="80" Margin="10"/>
                            </StackPanel>
                            <TextBlock Text="{Binding Path=menuText}" VerticalAlignment="Center" Margin="10" FontSize="20" />
                            <TextBlock Text="{Binding Path=menuPage}" Visibility="Collapsed" />
                        </StackPanel>
                    </Border>
                </DataTemplate>

                </ListBox.ItemTemplate>

        </ListBox>
相关阅读:
Top