In xaml Window.Resources I have defined a VisualBrush:
<VisualBrush x:Name="LineVisualBrush" x:Key="LineVisualBrush" TileMode="Tile" Viewport="0,0,40,40" ViewportUnits="Absolute" Viewbox="0,0,40,40" ViewboxUnits="Absolute" PresentationOptions:Freeze="True">
<VisualBrush.Visual>
<Grid Background="Black">
<Path Data="M 0 0 L 40 0" Stroke="White" />
</Grid>
</VisualBrush.Visual>
</VisualBrush>
In code behind I need to change the Grid Background Color and the Path Stroke Color:
VisualBrush vb = new VisualBrush();
vb = (VisualBrush)Resources["LineVisualBrush"];
vb.Visual.SetValue(Grid.BackgroundProperty, new SolidColorBrush(Colors.Red));
vb.Visual.SetValue(Shape.StrokeProperty, new SolidColorBrush(Colors.Blue));
The problem is that it set the Path Stroke Color to Red instead of Blue and it don't change the Grid Background Color.