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

The Archive Base Latest Questions

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

First; the question is rhetorical, I have an answer! I have gotten so much

  • 0

First; the question is rhetorical, I have an answer! I have gotten so much help from looking here that I wanted to give this neat trick back.

Imagine that you have a value that you want to bind to, but it is somehow or somewhat wrong.

  • I had a situation where I wanted to bind to a value, but when the value was 1, I needed 0, and vice-versa.
  • There was a time when I wanted to bind the width of an element to the width of a parent – 68px.
  • 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-20T01:06:34+00:00Added an answer on May 20, 2026 at 1:06 am

    Enter the FirstDegreeFunctionConverter:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Data;
    
    namespace GenericWPF
    {
        /// <summary>
        /// Will return a*value + b
        /// </summary>
        public class FirstDegreeFunctionConverter : IValueConverter
        {
            public double A { get; set; }
            public double B { get; set; }
    
            #region IValueConverter Members
    
            public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
            {
                double a = GetDoubleValue( parameter, A );
    
                double x = GetDoubleValue( value, 0.0 );
    
                return ( a * x ) + B;
            }
    
            public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
            {
                double a = GetDoubleValue( parameter, A );
    
                double y = GetDoubleValue( value, 0.0 );
    
                return ( y - B ) / a;
            }
    
            #endregion
    
    
            private double GetDoubleValue( object parameter, double defaultValue )
            {
                double a;
                if( parameter != null )
                    try
                    {
                        a = System.Convert.ToDouble( parameter );
                    }
                    catch
                    {
                        a = defaultValue;
                    }
                else
                    a = defaultValue;
                return a;
            }
        }
    }
    

    How to use it?

    You make a resource for each use in the resource section:

    <GenericWPF:FirstDegreeFunctionConverter x:Key="ReverseOne"
                                A="-1"
                                B="1" />
    
    <Border Opacity="{Binding Path=Opacity
        , ElementName=daOtherField
        , Converter={StaticResource ReverseOne}}" />
    
    <GenericWPF:FirstDegreeFunctionConverter x:Key="ListboxItemWidthToErrorWidth"
         A="1"
         B="-68" />
    
    <TextBox MaxWidth="{Binding Path=ActualWidth
       , Converter={StaticResource ListboxItemWidthToErrorWidth}
       , RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" />
    

    The name comes from the function y = ax + b (Called a "first degree function" in Norwegian), and of course it would be possible to upgrade it to a second degree function y= ax^2 + bx + c, but I haven’t found a use for it yet.

    I had a situation where I wanted to make columns based on width. Each time I got 200 pixels more width, I wanted the container to show me another column. At that time I hardcoded a converter, but I should have made a y=(a/x) + b converter instead.

    Now, what should I have named this converter so that everybody understand what it is? Since I’m a Norwegian, I used the expression we learned in school, directly translated. Please, if you have a suggestion or an opinion, let me know.
    Any refinements or improvements you have thought of would also be appreciated…


    Maybe "LinearTransformConverter" would better communicate what the converter does for you, I’ll think about it.
    Any other proposals?
    Tor

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

Sidebar

Related Questions

First question here and can I start by saying how much help this site
First question here: it is a very short yet fundamental thing in Java that
First question from me; I'm currently fixing a graphing service that uses XSLFO to
First question: ARMv5TE, ARMv6 and later have a Q flag that is set to
my first question is, where do I put this custom extension so that it
first question, hoping someone can help here. I've been trying to track down how
My first question here. The question is similar to this one: PHP: Retrying a
My first question here, hopefully I'm not doing it wrong. My problem is that
First question here, so please forgive me if this seems obvious. I'm having a
My first question. Please bear with me! I have an Ant task that need

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.