1

I want to use a VisualBrush in App.xaml:

<Application.Resources>
    <VisualBrush x:Key="TestBrush1" />
    <VisualBrush x:Key="TestBrush2" />
</Application.Resources>

Then I want to set a binding in one window like this:

VisualBrush testBrush = (VisualBrush)FindResource("TestBrush1");
Binding testBinding = new Binding();
testBinding.Source = FirstBrowser;
testBrush.Visual = testBinding;

And then I want to use this Brush to show the content of the FirstBrowser to another window. But that would come later. The binding does not work this way. Has someone an idea how I can make this work?

Marcel Grüger
  • 885
  • 1
  • 9
  • 25

1 Answers1

0

You cannot modify a VisualBrush that you have defined in App.xaml because it is frozen automatically by the runtime so defining a VisualBrush without a Visual as a global resource is useless.

You better create a new brush when you actually need it. You can bind the Visual property of a VisualBrush using the BindingOperations.SetBinding method like this:

VisualBrush testBrush = new VisualBrush();
BindingOperations.SetBinding(testBrush, VisualBrush.VisualProperty, new Binding() { Source = FirstBrowser });
mm8
  • 163,881
  • 10
  • 57
  • 88
  • But then I would have to call this brush from one window to another. Is this prossible and when yes, how is the performance... ok, I think I have to test it. – Marcel Grüger Jan 24 '17 at 13:18