更新: これは、VS2012 RC をインストールしてからです。(当たり前、ごめんなさいと言ったはずです)。私はWPFトグルボタンを持っています。その上に絵を描きたいので、描画ブラシを作成しました。描画の色を制御したいので、ToggleButton の Foreground プロパティにバインドしました。うまくいかないようですが?(次の例では、描画は青になる予定ですが、黒です)。
<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>
トレース出力
System.Windows.Data 警告: 55: バインディング (ハッシュ = 30868550) の BindingExpression (ハッシュ = 9381496) を作成しました System.Windows.Data 警告: 57: パス: 'Foreground' System.Windows.Data 警告: 59: BindingExpression (ハッシュ = 9381496): デフォルト モードは OneWay に解決されます System.Windows.Data 警告: 60 : BindingExpression (ハッシュ = 9381496): デフォルトの更新トリガーは PropertyChanged System.Windows.Data に解決されます 警告: 61 : BindingExpression (ハッシュ = 9381496): システムにアタッチします。 Windows.Media.Pen.Brush (ハッシュ = 13172414) System.Windows.Data 警告: 65 : BindingExpression (ハッシュ = 9381496): RelativeSource (FindAncestor) にはツリー コンテキストが必要です System.Windows.Data 警告: 64 : BindingExpression (ハッシュ = 9381496) : ソース保留の解決