Jenish Rabadiya
Jenish Rabadiya

Reputation: 6766

Wpf Custom ListBox with Rounded Border

I have extended ListBox control and wanted to give it rounded corner so I have applied styles as below and it works fine:

<control:MultiSelectionListBox SelectionMode="Extended" ItemsSource="{Binding Offerables,Mode=TwoWay}"
            SelectedItemsList="{Binding SelectedOfferables, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath="Name"
            Grid.Row="6" Grid.Column="0" MaxHeight="150">
    <control:MultiSelectionListBox.Resources>
        <Style TargetType="Border">
            <Setter Property="CornerRadius" Value="5"></Setter>
        </Style>
    </control:MultiSelectionListBox.Resources>
</control:MultiSelectionListBox>

but I have too many Listboxes and I don't wanted to add style in each and every control individually.

I wanted to define this style in app.xaml and wanted to reuse that design by name like Style = "{StaticResource RoundedListBoxStyle}".

I have tried like below in app.xaml but with no luck

<Style TargetType="ListBox" x:Key="RoundedListBoxStyle">
    <Setter Property="Border"  Value="10"></Setter>
</Style>

The member Border is not recognized or is not accessible.

Please guide me what I am doing wrong here.

Upvotes: 1

Views: 1352

Answers (1)

Jenish Rabadiya
Jenish Rabadiya

Reputation: 6766

Finally I managed to do that as Bradley Uffner mentioned in the comment Border is not the property of the ListBox and we cannot use it in style like that. I used Style.Resource and mentioned Style for Border elements as below:

<Style TargetType="ListBox" x:Key="RoundedListBoxStyle">
    <Style.Resources>
        <Style TargetType="Border">
            <Setter Property="CornerRadius" Value="5"></Setter>
        </Style>
    </Style.Resources>
</Style>

and it worked. :)

Upvotes: 2

Related Questions