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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:19:32+00:00 2026-06-08T19:19:32+00:00

UPDATE: This is since I installed VS2012 RC. (Duh, sorry should have said). I

  • 0

UPDATE: This is since I installed VS2012 RC. (Duh, sorry should have said).
I have a WPF Toggle Button. I want to draw a picture on it, so I made a Drawing Brush, I want to control the color of the drawing, so I bound it to the ToggleButton’s Foreground property. Don’t seem to work though? (in the following example, the drawing is meant to be blue, but it’s black).

<UserControl x:Class="SynthEditWpf.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
        <UserControl.Resources>

        <DrawingBrush x:Key="Power" Stretch="None">
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <DrawingGroup.Children>
                        <GeometryDrawing Geometry="F1 M 11.9999,4.34296L 11.9999,9.57471">
                            <GeometryDrawing.Pen>
                                <Pen Thickness="3" StartLineCap="Round" EndLineCap="Round" LineJoin="Round" Brush="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Control}}}"/>
                            </GeometryDrawing.Pen>
                        </GeometryDrawing>
                        <GeometryDrawing Geometry="F1 M 7.60373,6.78986C 6.09436,8.03101 5.13317,9.90375 5.13317,11.999C 5.13317,15.7359 8.19123,18.7654 11.9635,18.7654C 15.7359,18.7654 18.7939,15.7359 18.7939,11.999C 18.7939,9.90375 17.8327,8.03101 16.3234,6.78986">
                            <GeometryDrawing.Pen>
                                <Pen Thickness="3" StartLineCap="Round" EndLineCap="Round" LineJoin="Round" Brush="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Control}}}"/>
                            </GeometryDrawing.Pen>
                        </GeometryDrawing>
                    </DrawingGroup.Children>
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </UserControl.Resources>
    <Grid>
        <ToggleButton Foreground="Blue" Width="30" Height="30">
            <Rectangle Fill="{StaticResource Power}" Width="24" Height="24" />
        </ToggleButton>
    </Grid>
</UserControl>

TRACE OUTPUT

System.Windows.Data Warning: 55 : Created BindingExpression (hash=9381496) for Binding (hash=30868550)
System.Windows.Data Warning: 57 : Path: ‘Foreground’
System.Windows.Data Warning: 59 : BindingExpression (hash=9381496): Default mode resolved to OneWay
System.Windows.Data Warning: 60 : BindingExpression (hash=9381496): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 61 : BindingExpression (hash=9381496): Attach to System.Windows.Media.Pen.Brush (hash=13172414)
System.Windows.Data Warning: 65 : BindingExpression (hash=9381496): RelativeSource (FindAncestor) requires tree context
System.Windows.Data Warning: 64 : BindingExpression (hash=9381496): Resolve source deferred

  • 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-06-08T19:19:33+00:00Added an answer on June 8, 2026 at 7:19 pm

    This works for me. Ok, i better explain that hey. When it is just a brush as a resource it is not part of the rectangle. The ancestor it is finding is actually the userControl. Try changing the foreground of the user control and you will see it change the colour of your pen. To get it as part of the rectangle and therefore the togglebutton you need to wrap it in a style (see below)

    <Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">   
        <Window.Resources>
    
        <Style x:Key="Frank" TargetType="Rectangle">
            <Style.Resources>
                <DrawingBrush x:Key="Power" Stretch="None">
                    <DrawingBrush.Drawing>
                        <DrawingGroup>
                            <DrawingGroup.Children>
                                <GeometryDrawing Geometry="F1 M 11.9999,4.34296L 11.9999,9.57471">
                                    <GeometryDrawing.Pen>
                                        <Pen Thickness="3" StartLineCap="Round" EndLineCap="Round" LineJoin="Round" Brush="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton, Mode=FindAncestor}, Path=Foreground}"/>
                                    </GeometryDrawing.Pen>
                                </GeometryDrawing>
                                <GeometryDrawing Geometry="F1 M 7.60373,6.78986C 6.09436,8.03101 5.13317,9.90375 5.13317,11.999C 5.13317,15.7359 8.19123,18.7654 11.9635,18.7654C 15.7359,18.7654 18.7939,15.7359 18.7939,11.999C 18.7939,9.90375 17.8327,8.03101 16.3234,6.78986">
                                    <GeometryDrawing.Pen>
                                        <Pen Thickness="3" StartLineCap="Round" EndLineCap="Round" LineJoin="Round" Brush="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton, Mode=FindAncestor}, Path=Foreground}"/>
                                    </GeometryDrawing.Pen>
                                </GeometryDrawing>
                            </DrawingGroup.Children>
                        </DrawingGroup>
                    </DrawingBrush.Drawing>
                </DrawingBrush>
            </Style.Resources>
            <Setter Property="Fill" Value="{StaticResource Power}"/>
        </Style>
    </Window.Resources>
        <Grid>
            <ToggleButton Foreground="Blue" Width="30" Height="30">
                <Rectangle Style="{StaticResource Frank}" Width="24" Height="24"  />
            </ToggleButton>
        </Grid>
    

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

Sidebar

Related Questions

UPDATE : Since this question is getting some views, I figured I'd better highlight
UPDATE 1/31/10 : Since this thread continues to get a lot of views...I am
UPDATE: Facebook's API has changed a lot since this question was posted. This question
Update: This does work, I was being stupid :( i have the following extension
This is my first post here. I have been reading posts here since I
My Bash refuse to process to a databse update since I've installed gedmo for
The Arcana Elite Suite for Intraweb hasn't been updated since March 2008. Does this
Update : This is no longer an issue from C# 6, which has introduced
Update: This is, as I was told, no principle Python related problem, but seems
UPDATE: this is a repost of How to make shell scripts robust to source

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.