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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:05:10+00:00 2026-05-20T05:05:10+00:00

Below is the complete code for the example. I have a user control called

  • 0

Below is the complete code for the example. I have a user control called ColorPicker that contains 3 buttons each displaying a color. When a button is clicked the Color property in the CurrentSettings class is set. What I want to happen is the color of the rectangle on MainPage to change to match the new CurrentSettings.Color and the color of the rectangles (added in the code behind) in the listbox in the second user control to also change color to match the new CurrentSettings.Color.

I have been trying to accomplish this unsuccessfully using Dependency Properties and INotifyPropertyChanged and have now decided to start again with a clean slate.

// Current Sttings class:

public static class CurrentSettings
{
    public static Color Color { get; set; }
}

// MainPage XAML

<Grid x:Name="LayoutRoot">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="33*"/>
        <ColumnDefinition Width="33*"/>
        <ColumnDefinition Width="33*"/>
    </Grid.ColumnDefinitions>
    <local:ColorPicker/>
    <Rectangle Grid.Column="1" Name="rec" Width="160" Height="80" Fill="Yellow"/>
    <local:PenSelector Grid.Column="2"/>
</Grid>

// ColorPicker User Control XAML:

<StackPanel x:Name="LayoutRoot" Orientation="Horizontal">
    <Button x:Name="Red" Width="40" Height="40" Click="Red_Click">
        <Button.Content>
            <Rectangle Width="30" Height="30" Fill="Red"/>
        </Button.Content>
    </Button>
    <Button x:Name="Green" Width="40" Height="40" Click="Green_Click">
        <Button.Content>
            <Rectangle Width="30" Height="30" Fill="Green"/>
        </Button.Content>
    </Button>
    <Button x:Name="Blue" Width="40" Height="40" Click="Blue_Click">
        <Button.Content>
            <Rectangle Width="30" Height="30" Fill="Blue"/>
        </Button.Content>
    </Button>
</StackPanel>

// ColorPicker User Control Code Behind:

public partial class ColorPicker : UserControl
{
    public ColorPicker()
    {
        InitializeComponent();
    }

    private void Red_Click(object sender, RoutedEventArgs e)
    {
        CurrentSettings.Color = Colors.Red;
    }

    private void Green_Click(object sender, RoutedEventArgs e)
    {
        CurrentSettings.Color = Colors.Green;
    }

    private void Blue_Click(object sender, RoutedEventArgs e)
    {
        CurrentSettings.Color = Colors.Blue;
    }
}

// Pen Selector User Control XAML:

<ListBox x:Name="LayoutRoot"/>

// Pen Selector User Control XAML Code Behind:

public partial class PenSelector : UserControl
{
    public PenSelector()
    {
        InitializeComponent();

        LayoutRoot.Items.Add(new Rectangle() { Width = 160, Height = 80, Fill = new SolidColorBrush(Colors.Yellow) });
        LayoutRoot.Items.Add(new Rectangle() { Width = 160, Height = 80, Fill = new SolidColorBrush(Colors.Yellow) });
    }
}
  • 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-20T05:05:11+00:00Added an answer on May 20, 2026 at 5:05 am

    You were on the right track with INotifyPropertyChanged. Start with the settings class but make the Color setting an instance property on a class that implements INotifyPropertyChanged.

     public class CurrentSettings : INotifyPropertyChanged
     {
         private Color _Color;
         public Color Color
         {
            get { return _Color; }
            set { _Color = value; NotifyPropertyChanged("Color"); }
         }
         private void NotifyPropertyChanged(string name)
         {
             if (PropertyChanged != null)
                 PropertyChanged(this, new PropertyChangedEventArgs(name);
         }
         public event PropertyChangedEventHandler PropertyChanged;
     }
    

    Now place an instance of this in the Resources your App.Xaml:-

     <Application.Resources>
         <local:CurrentSettings x:Key="CurrentSettings" />
     </Application.Resources>
    

    Now add a CurrentSettings private property to your color picker:-

    private CurrentSettings CurrentSettings
    {
       get
       {
            return (CurrentSettings)Application.Current.Resources["CurrentSettings"];
       }
    }
    

    Finally use binding on the rectangle Fill property like this:-

    <Rectangle Grid.Column="1" Name="rec">
        <Rectangle.Fill>
             <SolidColorBrush Color="{Binding Color, Source={StaticResource CurrentSettings}}"/>
        </Rectangle.Fill>
    </Rectangle>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the simplest, fastest way to complete the PHP code below such that
Below I have a very simple example of what I'm trying to do. I
The code below makes complete sense to me - its about adding an element
Below is the code of a simple html with a table layout. In FF
The below code is writing unreadable characters to the text file: int main ()
Please help me to understand below code. This is the script for drag and
----Complete Rephrasing---- I was working on a new class where each instance was essentially
Below are two ways of reading in the commandline parameters. The first is the
Below is my current char* to hex string function. I wrote it as an
Below is part of the XML which I am processing with PHP's XSLTProcessor :

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.