Getting Started with WinUI Kanban Control

19 Dec 202418 minutes to read

This section provides a quick overview of how to get started with the WinUI Kanban control (SfKanban) for WinUI and a walk-through to configure the WinUI Kanban control in a real-time scenario. Follow the steps below to add WinUI Kanban control to your project.

Creating an application with WinUI Kanban

  1. Create a WinUI 3 desktop app for C# and .NET 6.

  2. Add reference to the Syncfusion.Kanban.WinUI NuGet.

  3. Import the control namespace Syncfusion.UI.Xaml.Kanban in XAML or C# code.

  4. Initialize the WinUI Kanban control.

    <Window
        ...
        xmlns:kanban="using:Syncfusion.UI.Xaml.Kanban">
    
        <kanban:SfKanban x:Name="kanban"/>
    </Window>
    using Syncfusion.UI.Xaml.Kanban;
    . . .
       
    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
            SfKanban kanban = new SfKanban();
            this.Content = kanban;
        }
    }

Populate WinUI Kanban item source

Here are the steps to render kanban card items using the WinUI Kanban control with the respective KanbanModel class.

  • Create view model.
  • Bind the item source for Kanban.

Create view model

Create a view model class to set values for the properties listed in the KanbanModel class as shown in the following example code. Each KanbanModel instance represents a card in the Kanban control.

  • ViewModel.cs
  • public class ViewModel
    {
        #region Properties
    
        /// <summary>
        /// Gets or sets the collection of <see cref="KanbanModel"/> objects representing tasks in various stages.
        /// </summary>
        public ObservableCollection<KanbanModel> TaskDetails { get; set; }
    
        #endregion
    
        #region Constructor
    
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModel"/> class.
        /// </summary>
        public ViewModel()
        {
            this.TaskDetails = this.GetTaskDetails();
        }
    
        #endregion
    
        #region Private methods
    
        /// <summary>
        /// Method to get the kanban model collections.
        /// </summary>
        /// <returns>The kanban model collections.</returns>
        private ObservableCollection<KanbanModel> GetTaskDetails()
        {
            var taskDetails = new ObservableCollection<KanbanModel>();
            string path = @"ms-appx:///";
    
            KanbanModel taskDetail = new KanbanModel();
            taskDetail.Title = "UWP Issue";
            taskDetail.Id = "651";
            taskDetail.Description = "Crosshair label template not visible in UWP";
            taskDetail.Category = "Open";
            taskDetail.IndicatorColorKey = "High";
            taskDetail.Tags = new List<string>() { "Bug Fixing" };
            taskDetail.Image = new Image
            {
                Source = new BitmapImage(new Uri("ms-appx:///Assets/Kanban/People_Circle1.png"))
            };
    
            taskDetails.Add(taskDetail);
    
            taskDetail = new KanbanModel();
            taskDetail.Title = "WinUI Issue";
            taskDetail.Id = "646";
            taskDetail.Description = "AxisLabel cropped when rotating the axis label";
            taskDetail.Category = "Open";
            taskDetail.IndicatorColorKey = "Low";
            taskDetail.Tags = new List<string>() { "Bug Fixing" };
            taskDetail.Image = new Image
            {
                Source = new BitmapImage(new Uri(path + "Assets/Kanban/People_Circle2.png"))
            };
    
            taskDetails.Add(taskDetail);
    
            taskDetail = new KanbanModel();
            taskDetail.Title = "Kanban Feature";
            taskDetail.Id = "25678";
            taskDetail.Description = "Provide drag and drop support";
            taskDetail.Category = "In Progress";
            taskDetail.IndicatorColorKey = "Low";
            taskDetail.Tags = new List<string>() { "New control" };
            taskDetail.Image = new Image
            {
                Source = new BitmapImage(new Uri(path + "Assets/Kanban/People_Circle3.png"))
            };
    
            taskDetails.Add(taskDetail);
    
            taskDetail = new KanbanModel();
            taskDetail.Title = "New Feature";
            taskDetail.Id = "29574";
            taskDetail.Description = "Dragging events support for Kanban";
            taskDetail.Category = "Closed";
            taskDetail.IndicatorColorKey = "Normal";
            taskDetail.Tags = new List<string>() { "New Control" };
            taskDetail.Image = new Image
            {
                Source = new BitmapImage(new Uri(path + "Assets/Kanban/People_Circle4.png"))
            };
    
            taskDetails.Add(taskDetail);
    
            taskDetail = new KanbanModel();
            taskDetail.Title = "WF Issue";
            taskDetail.Id = "1254";
            taskDetail.Description = "HorizontalAlignment for tooltip is not working";
            taskDetail.Category = "Review";
            taskDetail.IndicatorColorKey = "High";
            taskDetail.Tags = new List<string>() { "Bug fixing" };
            taskDetail.Image = new Image
            {
                Source = new BitmapImage(new Uri(path + "Assets/Kanban/People_Circle5.png"))
            };
    
            taskDetails.Add(taskDetail);
            return taskDetails;
        }
    
        #endregion
    }

    Bind item source for Kanban

    To populate the kanban card items, utilize the ItemsSource property of SfKanban.

    <kanban:SfKanban x:Name="kanban"
                     ItemsSource="{Binding TaskDetails}">
        <kanban:SfKanban.DataContext>
            <local:ViewModel/>
        </kanban:SfKanban.DataContext>
    </kanban:SfKanban>
    this.kanban.ItemsSource = new ViewModel().TaskDetails;

    binding-item-source-in-winui-kanban

    Defining columns

    The columns are generated automatically based on the different values of the Category in the KanbanModel class from the ItemsSource. However, you can manually define the columns by setting the AutoGenerateColumns property to false and adding KanbanColumn instances to the Columns property of SfKanban. You can define the column categories using the Categories property of KanbanColumn, and the cards will be added to their respective columns.

    <kanban:SfKanban x:Name="kanban"
                     AutoGenerateColumns="False" 
                     ItemsSource="{Binding TaskDetails}">
            <kanban:KanbanColumn HeaderText="To Do" Categories="Open" />
            <kanban:KanbanColumn HeaderText="In Progress" Categories="In Progress" />
            <kanban:KanbanColumn HeaderText="Done" Categories="Done" />
        <kanban:SfKanban.DataContext>
            <local:ViewModel/>
        </kanban:SfKanban.DataContext>
    </kanban:SfKanban>
    this.kanban.AutoGenerateColumns = false;
    this.kanban.ItemsSource = new ViewModel().TaskDetails;
    
    this.kanban.Columns.Add(new KanbanColumn() { HeaderText = "To Do", Categories = "Open" });
    this.kanban.Columns.Add(new KanbanColumn() { HeaderText = "In Progress", Categories = "In Progress" });
    this.kanban.Columns.Add(new KanbanColumn() { HeaderText = "Done", Categories = "Done" });
    
    public class ViewModel
    {
        #region Properties
    
        /// <summary>
        /// Gets or sets the collection of <see cref="KanbanModel"/> objects representing tasks in various stages.
        /// </summary>
        public ObservableCollection<KanbanModel> TaskDetails { get; set; }
    
        #endregion
    
        #region Constructor
    
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModel"/> class.
        /// </summary>
        public ViewModel()
        {
            this.TaskDetails = this.GetTaskDetails();
        }
    
        #endregion
    
        #region Private methods
    
        /// <summary>
        /// Method to get the kanban model collections.
        /// </summary>
        /// <returns>The kanban model collections.</returns>
        private ObservableCollection<KanbanModel> GetTaskDetails()
        {
            var taskDetails = new ObservableCollection<KanbanModel>();
            string path = @"ms-appx:///";
    
            KanbanModel taskDetail = new KanbanModel();
            taskDetail.Title = "UWP Issue";
            taskDetail.Id = "651";
            taskDetail.Description = "Crosshair label template not visible in UWP";
            taskDetail.Category = "Open";
            taskDetail.IndicatorColorKey = "High";
            taskDetail.Tags = new List<string>() { "Bug Fixing" };
            taskDetail.Image = new Image
            {
                Source = new BitmapImage(new Uri("ms-appx:///Assets/Kanban/People_Circle1.png"))
            };
    
            taskDetails.Add(taskDetail);
    
            taskDetail = new KanbanModel();
            taskDetail.Title = "WinUI Issue";
            taskDetail.Id = "646";
            taskDetail.Description = "AxisLabel cropped when rotating the axis label";
            taskDetail.Category = "Open";
            taskDetail.IndicatorColorKey = "Low";
            taskDetail.Tags = new List<string>() { "Bug Fixing" };
            taskDetail.Image = new Image
            {
                Source = new BitmapImage(new Uri(path + "Assets/Kanban/People_Circle2.png"))
            };
    
            taskDetails.Add(taskDetail);
    
            taskDetail = new KanbanModel();
            taskDetail.Title = "Kanban Feature";
            taskDetail.Id = "25678";
            taskDetail.Description = "Provide drag and drop support";
            taskDetail.Category = "In Progress";
            taskDetail.IndicatorColorKey = "Low";
            taskDetail.Tags = new List<string>() { "New control" };
            taskDetail.Image = new Image
            {
                Source = new BitmapImage(new Uri(path + "Assets/Kanban/People_Circle3.png"))
            };
    
            taskDetails.Add(taskDetail);
    
            taskDetail = new KanbanModel();
            taskDetail.Title = "New Feature";
            taskDetail.Id = "29574";
            taskDetail.Description = "Dragging events support for Kanban";
            taskDetail.Category = "In Progress";
            taskDetail.IndicatorColorKey = "Normal";
            taskDetail.Tags = new List<string>() { "New Control" };
            taskDetail.Image = new Image
            {
                Source = new BitmapImage(new Uri(path + "Assets/Kanban/People_Circle4.png"))
            };
    
            taskDetails.Add(taskDetail);
    
            taskDetail = new KanbanModel();
            taskDetail.Title = "WF Issue";
            taskDetail.Id = "1254";
            taskDetail.Description = "HorizontalAlignment for tooltip is not working";
            taskDetail.Category = "Done";
            taskDetail.IndicatorColorKey = "High";
            taskDetail.Tags = new List<string>() { "Bug fixing" };
            taskDetail.Image = new Image
            {
                Source = new BitmapImage(new Uri(path + "Assets/Kanban/People_Circle5.png"))
            };
    
            taskDetails.Add(taskDetail);
            return taskDetails;
        }
    
        #endregion
    }

    NOTE

    When manually defining columns, ensure the AutoGenerateColumns property of SfKanban is set to false.

    defining-columns-in-winui-kanban

    Theme

    The WinUI Kanban supports light and dark themes, automatically adjusting to the system’s theme settings for a consistent and visually appealing experience in any environment.

    Refer to the following link for guidance on applying themes: Themes for Syncfusion WinUI controls

    You can find the kanban keys for all themes in this theme resource file..

    Localization

    The WinUI Kanban control supports the localization of all static default strings, allowing you to translate them into any supported language. For detailed instructions on how to localize the default strings, refer to the following link: Localization in WinUI controls.

    Right to Left (RTL)

    The WinUI Kanban control supports RTL (Right-to-Left) rendering, allowing both text and the control’s layout to be displayed from right to left. For more information on how to enable RTL rendering, please refer to the following link: Right to left in WinUI controls.

    NOTE

    You can refer to our WinUI Kanban feature tour page for its groundbreaking feature representations. You can also explore our WinUI Kanban Examples that shows you how to render the Kanban in WinUI.