WPF Round Corner ListBox

Describes to create a custom list box control in WPF which has round corner border for list box and item using XAML Code.

WPF Round Corner ListBox

Getting Started

WPF provides list box control with border option where we can change border color and thickness of the border, but we can change the corner radio to make the list box border to round corner border directly.

Same as you cannot change the border of an item of list box item because both the list box border and item container border of the list box is by default encapsulated.

There are different ways of achieving around the corner border, but here in this blog, I achieved by simply using the style in the list box.

The reason for using the style is that the WPF list box container. You cannot get a button feature directly with the list box, but using the style you can target the hidden border of the list box. Also, the item contents of the list box contain a hidden border can be targeted as well.

For targeting style to list box hidden border, here the list box resource is used and applied the style for the hidden border. For Item container hidden border item container’s style has been used here and inside the resource, the custom style is targeted to the hidden border. Go through the below code example for more details

Example


The below example creates a custom list box that has a round corner border and round corner item container with displays list box items in round shape.

XAML Code:
 <ListBox Name="listBoxZone" ItemsSource="{Binding TheList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="62,31,69,24" Padding="11,20">  
         <ListBox.Resources>  
           <Style TargetType="Border">  
             <Setter Property="CornerRadius" Value="15"/>  
         </Style>  
         </ListBox.Resources>  
         <ListBox.ItemTemplate>  
           <DataTemplate>  
           <TextBlock Text="{Binding TheText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBlock>  
           </DataTemplate>  
         </ListBox.ItemTemplate>  
       <ListBox.ItemContainerStyle>  
         <Style TargetType="ListBoxItem">  
           <Style.Resources>  
             <Style TargetType="Border">  
               <Setter Property="CornerRadius" Value="5"/>  
             </Style>  
           </Style.Resources>  
         </Style>  
       </ListBox.ItemContainerStyle>  
     </ListBox>  

C# Code: For Data

  private void FillList()  
     {  
       TheList.Add(new BoolStringClass() { TheText = "Student1", IsSelected = false });  
       TheList.Add(new BoolStringClass() { TheText = "Student2", IsSelected = false });  
       TheList.Add(new BoolStringClass() { TheText = "Student3", IsSelected = false });  
       TheList.Add(new BoolStringClass() { TheText = "Student4", IsSelected = false });  
       TheList.Add(new BoolStringClass() { TheText = "Student5", IsSelected = false });  
       //this.listBoxZone.ItemsSource = this.TheList;  
       this.DataContext = this;  
     }  
WPF ListBox

WPF Round Corner ListBox

Related Articles

  1. Data Validation in WPF
  2. WPF Round Corner Button with click effects
  3. Round Corner PasswordBox in WPF
  4. Round Corner TextBox in WPF
  5. WPF Custom Datagrid Control(Filterable)
  6. WPF Round Corner ListBox
  7. Custom RadioButtonListBox With Image
  8. RadiobuttonList in WPF
  9. Custom CheckedListBox in WPF

Thanks

Kailash Chandra Behera

An IT Professional with 12 years experience in development life cycle in windows, service and Web based application using Microsoft.Net technologies. Proven record of developing all phases of projects in Microsoft.Net technology from initiation to closure aligning with the company's Business objectives to drive process improvements, competitive advantage and bottom-line gains. -> Good exposure of independently working and developing multiple projects ->Committed to efficient and effective development of projects in a fast-paced and deadline driver environment. Skill :- Develop and design projects in various technologies of Microsoft Technology. Total IT Experience- 13+

Previous Post Next Post

نموذج الاتصال