Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello coders, I am having some trouble trying to convert a string to a image and set it as the background and I do not know what is wrong with my code and the error (System.Windows.Markup.XamlParseException: ''Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '11' and line position '14'.') pops up, if someone could help me it would me very much appreciated.

What I have tried:

private void Background1_clicked(object sender, RoutedEventArgs e)
        {
            string Background = "images/background.png";
            Change_background(Background);
        }

        public void Change_background(string Background)
        {
            var converter1 = new BrushConverter();
            var Background_set = (ImageBrush)converter1.ConvertFromString(Background);
            Grid1.Background = Background_set;
        }
Posted
Updated 11-Aug-19 23:04pm

1 solution

The string needs to be a text representation of an object that can be used as a brush colour, as shown in this example: BrushConverter.ConvertFromString, System.Windows.Media C# (CSharp) Code Examples - HotExamples[^]. You could try loading the image as a drawable object and see if it can create a brush from the object.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900