Click here to Skip to main content
15,921,837 members
Home / Discussions / C#
   

C#

 
GeneralRe: Passing Parameters in Windows Service Installation Pin
Arun Abraham Jose13-Jan-08 22:51
Arun Abraham Jose13-Jan-08 22:51 
QuestionHow to transfer Excel data sheet to an Access Table Pin
rameshika13-Jan-08 17:20
rameshika13-Jan-08 17:20 
GeneralRe: How to transfer Excel data sheet to an Access Table Pin
pmarfleet13-Jan-08 19:44
pmarfleet13-Jan-08 19:44 
GeneralRe: How to transfer Excel data sheet to an Access Table Pin
MickCurley14-Jan-08 1:13
MickCurley14-Jan-08 1:13 
GeneralRe: How to transfer Excel data sheet to an Access Table Pin
pmarfleet14-Jan-08 2:42
pmarfleet14-Jan-08 2:42 
QuestionWPF - Changing Fill property for group of shapes Pin
Shawn Horton13-Jan-08 16:25
Shawn Horton13-Jan-08 16:25 
GeneralRe: WPF - Changing Fill property for group of shapes Pin
CKnig14-Jan-08 0:46
CKnig14-Jan-08 0:46 
GeneralRe: WPF - Changing Fill property for group of shapes [modified] Pin
Shawn Horton14-Jan-08 7:06
Shawn Horton14-Jan-08 7:06 
I guess I am not being to helpful to myself. I just want to create a custom control with two ellipses with a variable fill color that can be changed at runtime.

The control would have a property dialog with a color picker, that would change the ellipse fill color to the selected color. That is all I need.
I know I could set the fill color of each ellipse independently by modifying the Fill property in the codebehind, but I was looking for a way to just change a single "color" variable and save myself some work.

I have been trying every combination of resource, dynamic property, and anything else I can find, and I posted some code somewhere between changes.

Thanks for any help you can give.

Shawn
<UserControl x:Class="WpfCustomControlLibrary2.UserControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300">
   <UserControl.Resources>
        <SolidColorBrush x:Key="SolidBrush" Color="#FF00FFFF"/>
    <UserControl.Resources>
    <Grid>
        <Ellipse Height="27" HorizontalAlignment="Left" Margin="50,42,0,0" Name="ellipse1" Stroke="Black" Fill="{DynamicResource SolidBrush}" VerticalAlignment="Top" Width="46" />
        <Ellipse Height="27" HorizontalAlignment="Left" Margin="10,10,0,0" Name="ellipse2" Stroke="Black" Fill="{DynamicResource SolidBrush}" VerticalAlignment="Top" Width="46" />
    </Grid>
<UserControl>

In the control's code behind file:
SolidColorBrush _FillColor;   //I want this variable to control the DynamicResource SolidBrush

//Property to change fill color
 public SolidColorBrush SolidBrush
        {
            get
            {
                return (SolidColorBrush) _FillColor;
            }
            set
            {
                _FillColor = value;
            }
        }


I got an answer from the MSDN Forums

<UserControl x:Class="WpfCustomControlLibrary2.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Height="300" Width="300">
     <Grid>
          <Ellipse Height="27" HorizontalAlignment="Left" Margin="50,42,0,0" Name="ellipse1" Stroke="Black" Fill="{Binding Path=SolidBrush}"                                   VerticalAlignment="Top" Width="46" />
          <Ellipse Height="27" HorizontalAlignment="Left" Margin="10,10,0,0" Name="ellipse2" Stroke="Black" Fill="{Binding Path=SolidBrush}" VerticalAlignment="Top" Width="46" />
     </Grid>
<UserControl>


OR
<UserControl x:Class="WpfCustomControlLibrary2.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
     <Grid>
          <Ellipse Height="27" HorizontalAlignment="Left" Margin="50,42,0,0" Name="ellipse1" Stroke="Black" Fill="{Binding Path=SolidBrush,  RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" VerticalAlignment="Top" Width="46" />
          <Ellipse Height="27" HorizontalAlignment="Left" Margin="10,10,0,0" Name="ellipse2" Stroke="Black" Fill="{Binding Path=SolidBrush, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" VerticalAlignment="Top" Width="46" />
     </Grid>
<UserControl>


And change the code behind to:

public static readonly DependencyProperty SolidBrushProperty = DependencyProperty.Register("SolidBrush", typeof(SolidColorBrush), typeof(UserControl1), new UIPropertyMetadata(null));

        public SolidColorBrush SolidBrush
        {
            get { return (SolidColorBrush)GetValue(SolidBrushProperty); }
            set { SetValue(SolidBrushProperty, value); }
        }


Maybe this helps someone else.

modified on Monday, January 14, 2008 7:12:32 PM

GeneralRe: WPF - Changing Fill property for group of shapes Pin
CKnig14-Jan-08 18:46
CKnig14-Jan-08 18:46 
GeneralRe: WPF - Changing Fill property for group of shapes Pin
Shawn Horton15-Jan-08 1:17
Shawn Horton15-Jan-08 1:17 
Generaldeveloping fingerprint software using c# Pin
ayie13-Jan-08 16:22
ayie13-Jan-08 16:22 
GeneralRe: developing fingerprint software using c# Pin
Vasudevan Deepak Kumar13-Jan-08 18:17
Vasudevan Deepak Kumar13-Jan-08 18:17 
GeneralRe: developing fingerprint software using c# Pin
ayie15-Jan-08 21:14
ayie15-Jan-08 21:14 
GeneralSp Pin
new2pgrmg13-Jan-08 16:09
new2pgrmg13-Jan-08 16:09 
GeneralRe: Sp Pin
tcsoccerman13-Jan-08 16:17
tcsoccerman13-Jan-08 16:17 
GeneralRe: Sp Pin
new2pgrmg13-Jan-08 17:06
new2pgrmg13-Jan-08 17:06 
GeneralRe: Sp Pin
new2pgrmg15-Jan-08 5:00
new2pgrmg15-Jan-08 5:00 
GeneralThe value of message box Pin
Strategic_Thinker13-Jan-08 5:27
Strategic_Thinker13-Jan-08 5:27 
GeneralRe: The value of message box Pin
tcsoccerman13-Jan-08 5:30
tcsoccerman13-Jan-08 5:30 
GeneralRe: The value of message box Pin
Strategic_Thinker13-Jan-08 7:00
Strategic_Thinker13-Jan-08 7:00 
GeneralRe: The value of message box Pin
Christian Graus13-Jan-08 9:20
protectorChristian Graus13-Jan-08 9:20 
JokeRe: The value of message box Pin
Steve Echols13-Jan-08 21:14
Steve Echols13-Jan-08 21:14 
GeneralRe: The value of message box Pin
Paul Conrad13-Jan-08 6:30
professionalPaul Conrad13-Jan-08 6:30 
QuestionVScrollBar and VisibleArea Pin
tcsoccerman13-Jan-08 4:08
tcsoccerman13-Jan-08 4:08 
GeneralRe: VScrollBar and VisibleArea Pin
Luc Pattyn13-Jan-08 4:55
sitebuilderLuc Pattyn13-Jan-08 4:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.