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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:15:03+00:00 2026-05-13T09:15:03+00:00

I have a custom class, FavoriteColor that has three properties, R , G and

  • 0

I have a custom class, “FavoriteColor” that has three properties, R, G and B. Now I want to draw a rectangle and fill it with these R, G and B values (using databinding). I tried the following snippet in my xaml, but gives me a compile time error.

                <Rectangle Width="10" Height="10" Grid.Column="4">
                    <Rectangle.Fill>
                        <SolidColorBrush>
                            <SolidColorBrush.Color>
                                <Color R="{Binding Path=R}" />
                                <Color G="{Binding Path=G}" />
                                <Color B="{Binding Path=B}" />
                            </SolidColorBrush.Color>
                        </SolidColorBrush>
                    </Rectangle.Fill>
                </Rectangle>

It says that the properties R, G and B of Color class are not dependency properties. I know that you can bind data only to dependency properties, but in this case, how do I bind my R, G and B with the rectangle’s fill color.

Is there any other way other than by declaring one more property of type color and then initializing it when R, G and B are set? Also why the R, G and B of the color class are not dependency properties?

  • 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-13T09:15:03+00:00Added an answer on May 13, 2026 at 9:15 am

    Let’s do this using a MultiBinding and an IMultiValueConverter. Here’s a full sample.

    First, the xaml for Window1. We’ll set up three Sliders and bind their values to the Window’s Background property via a SolidColorBrush.

    <Window x:Class="WpfApplication16.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:my="clr-namespace:WpfApplication16"
        Title="Window1" Height="300" Width="300">
        <Window.Resources>
            <my:RgbConverter x:Key="RgbConverter" />
        </Window.Resources>
        <Window.Background>
            <SolidColorBrush>
                <SolidColorBrush.Color>
                    <MultiBinding Converter="{StaticResource RgbConverter}">
                        <Binding Path="Value" ElementName="redSlider" />
                        <Binding Path="Value" ElementName="greenSlider" />
                        <Binding Path="Value" ElementName="blueSlider" />
                    </MultiBinding>
                </SolidColorBrush.Color>
            </SolidColorBrush>
        </Window.Background>
        <StackPanel>
            <Slider Minimum="0" Maximum="255" x:Name="redSlider" />
            <Slider Minimum="0" Maximum="255" x:Name="greenSlider" />
            <Slider Minimum="0" Maximum="255" x:Name="blueSlider" />
        </StackPanel>
    </Window>
    

    Next, the converter. Note that I’m not doing any error checking here – you really should check that the length of the values array is 3 and that the individual values are valid bytes etc.

    public class RgbConverter : IMultiValueConverter
    {
        #region IMultiValueConverter Members
    
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var r = System.Convert.ToByte(values[0]);
            var g = System.Convert.ToByte(values[1]);
            var b = System.Convert.ToByte(values[2]);
    
            return Color.FromRgb(r, g, b);
        }
    
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    
        #endregion
    }
    

    That’s it! No other code-behind is necessary.

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

Sidebar

Related Questions

I have a custom class that has as an instance variable of a coordinate:
I have a custom class, and that class has a UIButton instance variable. I
I have a custom class Foo with properties A and B. I want to
I have a custom class which I want to load inside the firstViewController and
I have a custom class that uses boost mutexes and locks like this (only
I have a custom class say 'MyCanvas' derived from wpf Canvas class. MyCanvas has
I have a custom class that I use to build table strings. I would
I have a custom class that extends Preference that I'm using in conjunction with
I have a custom class Spieltag containing a property SpieltagDaten (custom class). SPieltagDaten has
I have a custom class in F# and I want to implement the []

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.