Skip to content

Fix SegmentBackground not being drawn when StrokeThickness is set to 0 #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 24, 2025

Problem

When StrokeThickness is set to 0 on SfSegmentedControl, the SegmentBackground color disappears and becomes virtually transparent, even when explicitly set to a color.

<segmentedControl:SfSegmentedControl SegmentBackground="Red" StrokeThickness="0">
    <segmentedControl:SfSegmentedControl.ItemsSource>
        <x:Array Type="{x:Type x:String}">
            <x:String>Day</x:String>
            <x:String>Week</x:String>
            <x:String>Month</x:String>
            <x:String>Year</x:String>
        </x:Array>
    </segmentedControl:SfSegmentedControl.ItemsSource>
</segmentedControl:SfSegmentedControl>

Expected: Red background with no border stroke
Actual: Transparent background

Root Cause

In SegmentItemView.DrawRoundedRectangle(), the method had an early return condition that prevented drawing when StrokeThickness == 0:

if (itemInfo?.SegmentTemplate != null || itemInfo == null || itemInfo.StrokeThickness == 0)
{
    return; // This prevented background from being drawn!
}

Solution

Modified the drawing logic to:

  1. Always draw the background when SegmentBackground is set
  2. Only draw stroke when StrokeThickness > 0
  3. Handle corner radius correctly for both scenarios

Key Changes

  • Removed StrokeThickness == 0 from early return condition
  • Separated background and stroke drawing logic
  • Added conditional stroke drawing based on thickness value
  • Updated corner radius calculations to handle zero stroke thickness

Before/After

Before:

// Early return prevented any drawing
if (itemInfo.StrokeThickness == 0) return;

// Background and stroke drawn together
canvas.FillRoundedRectangle(...);  // Never reached when thickness = 0

After:

// Always draw background
canvas.FillRoundedRectangle(...);

// Only draw stroke when needed
if (itemInfo.StrokeThickness > 0)
{
    canvas.DrawRoundedRectangle(...);
}

Testing

Added comprehensive test cases to verify:

  • SegmentBackground property is preserved when StrokeThickness = 0
  • GetSegmentBackground() helper returns correct values regardless of stroke thickness
  • No regression in existing functionality

Fixes #191.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] [1.0.5] SegmentBackground is not evaluated if StrokeThickness is set to 0. Fix SegmentBackground not being drawn when StrokeThickness is set to 0 Jun 24, 2025
@Copilot Copilot AI requested a review from PaulAndersonS June 24, 2025 06:10
Copilot finished work on behalf of PaulAndersonS June 24, 2025 06:10
@PaulAndersonS PaulAndersonS added this to the v1.0.6 milestone Jun 24, 2025
@PaulAndersonS
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Jeyasri-Murugan Jeyasri-Murugan marked this pull request as ready for review June 25, 2025 03:58
@PaulAndersonS PaulAndersonS merged commit fa3de97 into main Jun 25, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Done in MAUI Toolkit Development Board Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

[1.0.5] SegmentBackground is not evaluated if StrokeThickness is set to 0.
3 participants