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 4123040
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:33:37+00:00 2026-05-20T23:33:37+00:00

To have less redundant XAML markup i try to get a radiobutton-type selection control

  • 0

To have less redundant XAML markup i try to get a radiobutton-type selection control to be populated generically, i.e. i use an ItemsControl with an enum as ItemsSource and create a DataTemplate which shows which item is selected by checking whether the enum value of the item is the same as the current setting.

This alone cannot be done using a simple converter or DataTrigger because two bindings are needed, so i created a generic MutliValueConverter to check for equality:

<CheckBox.Visibility>
    <MultiBinding Converter="{StaticResource EqualityComparisonConv}">
        <Binding Path="Key"/>
        <Binding Path="DisplayMode_Current" Source="{x:Static local:App.Settings}"/>
    </MultiBinding>
</CheckBox.Visibility>
public class EqualityComparisonConverter : IMultiValueConverter
{
    #region IMultiValueConverter Members

    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        if (values.Length < 2) throw new Exception("At least two inputs are needed for comparison");
        bool output = (bool)values.Skip(1).Aggregate(values[0], (x1, x2) => { return x1.Equals(x2); });
        return output;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        throw new NotSupportedException();
    }

    #endregion
}

The obvious problem here is that the converter returns a boolean which i would need to convert to Visibility first.

Wrapping the MultiBinding in another binding with just a converter does not work because the properties are not dependency properties (hence cannot have a binding assigned to them). I could think of a few workarounds like storing the bool in some Tag property, so i can use that as a new binding source, but i would be more interested in something like this:

<CheckBox.Visibility>
    <local:PipeConverter Converter="{StaticResource BooleanToVisibilityConv}">
        <MultiBinding Converter="{StaticResource EqualityComparisonConv}">
            <Binding Path="Key"/>
            <Binding Path="DisplayMode_Current" Source="{x:Static local:App.Settings}"/>
        </MultiBinding>
    </local:PipeConverter>
</CheckBox.Visibility>

This class would need to update its output when changes in the original binding occur and it would need to be able to expose its output value to the Visibility property but i do not know how to achieve either. One problem one runs into is that there is a need for dependency properties so inheriting from DependencyObject would be nice, but inheriting from a Binding class would also make sense because the PipeConverter should bind and needs to be set as the value of another dependency property.

  • 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-20T23:33:37+00:00Added an answer on May 20, 2026 at 11:33 pm

    Three options:

    Option A: Convert your bool to visibility in your multivalueconverter (its just one line)

    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        if (values.Length < 2)
            throw new Exception("At least two inputs are needed for comparison");
        bool output = (bool)values.Skip(1).Aggregate(values[0], (x1, x2) =>
             { return x1.Equals(x2); });
        return output ? Visibility.Visible : Visibility.Collapsed;
    }
    

    Option B: Use the existing booltovisibilityconverter programatically

    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        if (values.Length < 2)
            throw new Exception("At least two inputs are needed for comparison");
        bool output = (bool)values.Skip(1).Aggregate(values[0], (x1, x2) =>
             { return x1.Equals(x2); });
        System.Windows.Controls.BooleanToVisibilityConverter booltovisibilityconverter = new System.Windows.Controls.BooleanToVisibilityConverter();
        return booltovisibilityconverter.Convert(output, System.Type.GetType("System.Boolean"), parameter, culture);
    }
    

    PS: You may want to cache the booltovisibilityconverter instead of creating it everytime.

    Option C: Pipe your converters

    Piping Value Converters in WPF

    PS: Beaware that this article is quite old.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just installed darcs 2.1.2.2. When I type darcs help, sth less-like shows
I have downloaded a font that looks less than desirable if it is not
We have a setup here that is less than ideal, We have our webserver
I have a short preliminary interview with Microsoft in less than 2 hours. I've
I have a script that loops through a series of four (or less) characters
I have a variety of time-series data stored on a more-or-less georeferenced grid, e.g.
I can't make td Date to have fixed height. If there is less in
I have the following text: <i><b>It is noticeably faster.</b></i> <i><b>They take less disk space.</i>
Some product serial numbers are of type varchar and have a letter indicating the
Have just started using Google Chrome , and noticed in parts of our site,

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.