Click here to Skip to main content
14,328,292 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100