I want to let the user customize the background of of my application and select either a color or an image WITH an opacity binding. I want to do this in XAML if possible.
I seem to be very close - the code below works great with either the color OR the image brush (if I comment out the other), but I cannot figure out a way on how to return the appropriate brush depending on a boolean (UseBackgroundImage).
If you look in the code below you can see I have commented out the ImageBrush - I tried putting in a VisibilityConverter bound to UseBackgroundImage but the Brush object does not use the Visibility property.
I thought about writing a converter to return the appropriate brush but then I can't figure out how to apply the Opacity to just the background (it applies to the all the content).
<navigation:Frame>
<navigation:Frame.Background>
<SolidColorBrush Color="{Binding Config.BackgroundColorInfo.Value}" Opacity="{Binding Config.BackgroundOpacity}" />
<!--<ImageBrush ImageSource="/TourneyManager;component/image.JPG" Stretch="UniformToFill" Opacity="{Binding Config.BackgroundOpacity}"/>-->
</navigation:Frame.Background>
<navigation:Frame.UriMapper>
I then tried setting the bindings in the code behind like this:
SolidColorBrush backgroundBrush = new SolidColorBrush();
Binding b = new Binding("Config.BackgroundColorInfo.Value");
ContentFrame.SetBinding(SolidColorBrush.ColorProperty, b);
Binding b1 = new Binding(".BackgroundOpacity");
ContentFrame.SetBinding(SolidColorBrush.OpacityProperty, b1);
ContentFrame.Background = backgroundBrush;
But the SolidColorBrush class does not have the SetBinding method, so no joy there.
Any suggestions on how to achieve this please?