Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5841289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:52:17+00:00 2026-05-22T11:52:17+00:00

Let’s say I have a Border whose DataContext is an object of type MyViewModel.

  • 0

Let’s say I have a Border whose DataContext is an object of type MyViewModel. MyViewModel has bool properties called RoundLeft and RoundRight. When RoundLeft is true, I want the CornerRadius of the border to be 6,0,0,6. When RoundRight is true, I want 0,6,6,0. When both are true, I want 6,6,6,6.

I’ve described my first two attempts below. I haven’t given up yet, but I wanted to see if anyone else might have any ideas.

Attempt #1

I got it partially working by binding to the MyViewModel instance itself (not a specific property) and using an IValueConverter that builds the correct CornerRadius object. This works on initial load. The problem is that the binding is monitoring changes of the object as a whole rather than changes to the specific RoundLeft and RoundRight properties, e.g. if RoundLeft changes, the border’s CornerRadius doesn’t.

Binding:

<Border CornerRadius="{Binding Converter={StaticResource myShiftCornerRadiusConverter}}" />

Converter:

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        var myViewModel = value as MyViewModel;
        if (myViewModel != null)
        {
            return new CornerRadius(
                myViewModel.RoundLeft ? 6 : 0,
                myViewModel.RoundRight ? 6 : 0,
                myViewModel.RoundRight ? 6 : 0,
                myViewModel.RoundLeft ? 6 : 0);
        }
        else
        {
            return new CornerRadius(6);
        }
    }

Attempt #2

This blog post from Colin Eberhardt looked promising, but I’m getting vague XamlParseExceptions and ComExceptions. Here’s my XAML:

<Border>
<ce:MultiBindings>
    <ce:MultiBinding TargetProperty="CornerRadius" Converter="{StaticResource myCornerRadiusConverter}">
        <ce:MultiBinding.Bindings>
            <ce:BindingCollection>
                <Binding Path="RoundLeft" />
                <Binding Path="RoundRight" />
            </ce:BindingCollection>
        </ce:MultiBinding.Bindings>
    </ce:MultiBinding>
</ce:MultiBindings>
</Border>

Here’s my converter, although the execution never gets this far, i.e. my breakpoint is never hit.

public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (values.Length == 2 && values.All(v => v is bool))
        {
            var roundLeft = (bool)values[0];
            var roundRight = (bool)values[1];

            return new CornerRadius(
                roundLeft ? 6 : 0,
                roundRight ? 6 : 0,
                roundRight ? 6 : 0,
                roundLeft ? 6 : 0);
        }
        else
        {
            return new CornerRadius(6);
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:52:18+00:00Added an answer on May 22, 2026 at 11:52 am

    I implemented the approach @Foovanadil suggested, but then I got another idea: I created a new ContentControl that exposes RoundLeft and RoundRight dependency properties. It certainly involved more code, but now the CornerRadius stuff is all in the View layer.

    [TemplatePart(Name = _borderPartName, Type = typeof(Border))]
    public class CustomRoundedBorder : ContentControl
    {
        #region Private Fields
    
        private const string _borderPartName = "PART_Border";
        private Border _borderPart;
    
        #endregion
    
        #region Dependency Properties
    
        #region DefaultCornerRadius
    
        //////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Gets or sets the default corner radius, in pixels.
        /// </summary>
        //////////////////////////////////////////////////////////////////////////////
        public double DefaultCornerRadius
        {
            get { return (double)GetValue(DefaultCornerRadiusProperty); }
            set { SetValue(DefaultCornerRadiusProperty, value); }
        }
    
        public static readonly DependencyProperty DefaultCornerRadiusProperty = DependencyProperty.Register(
            "DefaultCornerRadius", typeof(double), typeof(CustomRoundedBorder),
            new PropertyMetadata(new PropertyChangedCallback(RoundingChanged)));
    
        #endregion
    
        #region RoundLeft
    
        //////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Gets or sets a value indicating whether to round the corners on the left side of the border.
        /// </summary>
        //////////////////////////////////////////////////////////////////////////////
        public bool RoundLeft
        {
            get { return (bool)GetValue(RoundLeftProperty); }
            set { SetValue(RoundLeftProperty, value); }
        }
    
        public static readonly DependencyProperty RoundLeftProperty = DependencyProperty.Register(
            "RoundLeft", typeof(bool), typeof(CustomRoundedBorder),
            new PropertyMetadata(new PropertyChangedCallback(RoundingChanged)));
    
        #endregion
    
        #region RoundRight
    
        //////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Gets or sets a value indicating whether to round the corners on the left side of the border.
        /// </summary>
        //////////////////////////////////////////////////////////////////////////////
        public bool RoundRight
        {
            get { return (bool)GetValue(RoundRightProperty); }
            set { SetValue(RoundRightProperty, value); }
        }
    
        public static readonly DependencyProperty RoundRightProperty = DependencyProperty.Register(
            "RoundRight", typeof(bool), typeof(CustomRoundedBorder),
            new PropertyMetadata(new PropertyChangedCallback(RoundingChanged)));
    
        #endregion
    
        #region EffectiveCornerRadius
    
        //////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Gets the effective corner radius, based on DefaultCornerRadius and 
        /// RoundLeft and RoundRight.
        /// </summary>
        //////////////////////////////////////////////////////////////////////////////
        public double EffectiveCornerRadius
        {
            get { return (double)GetValue(EffectiveCornerRadiusProperty); }
            private set { SetValue(EffectiveCornerRadiusProperty, value); }
        }
    
        public static readonly DependencyProperty EffectiveCornerRadiusProperty = DependencyProperty.Register(
            "EffectiveCornerRadius", typeof(double), typeof(CustomRoundedBorder),
            new PropertyMetadata(new PropertyChangedCallback(RoundingChanged)));
    
        #endregion
    
        #endregion
    
        #region Overrides
    
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
    
            this._borderPart = this.GetTemplateChild(_borderPartName) as Border;
            this.UpdateCornerRadius();
        }
    
        #endregion
    
        #region Private Methods
    
        private static void RoundingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = d as CustomRoundedBorder;
            if (control != null)
            {
                control.UpdateCornerRadius();
            }
        }
    
        private void UpdateCornerRadius()
        {
            if (this._borderPart != null)
            {
                this._borderPart.CornerRadius = new CornerRadius(
                    this.RoundLeft ? this.DefaultCornerRadius : 0,
                    this.RoundRight ? this.DefaultCornerRadius : 0,
                    this.RoundRight ? this.DefaultCornerRadius : 0,
                    this.RoundLeft ? this.DefaultCornerRadius : 0);
            }
        }
    
        #endregion
    }
    

    Then I created a ControlTemplate for it (some properties omitted for brevity):

    <ControlTemplate x:Key="MyBorderTemplate" TargetType="ce:CustomRoundedBorder">
        <Border
            x:Name="PART_Border"
            CornerRadius="{TemplateBinding EffectiveCornerRadius}"
            >
            <ContentPresenter />
        </Border>
    </ControlTemplate>
    

    Then here’s where I bound it to the view-model properties:

    <ce:CustomRoundedBorder
        DefaultCornerRadius="6"
        RoundLeft="{Binding RoundLeft}"
        RoundRight="{Binding RoundRight}"
        Template="{StaticResource MyBorderTemplate}"
        >
        <!-- Content -->
    </ce:CustomRoundedBorder>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.