Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Invalid Uri: webBrowser DependencyProperty pulling partial string

$
0
0

I'm binding datagrid cell content to a webBrowser and getting an "invalid URI" error.

I've tried converting string to Absolute URI (below), but it doesn't fix the error. It appears the partial value is getting retrieved before I'm able to convert it. For instance: my error shows e.NewValue's value as "A.pdf" instead of the entire (absolute) path "file:///C:/Users/Documents/A.pdf". I haven't been able to find mention of this anywhere and have been searching for day - any ideas?

    public class WebBrowserUtility
    {
        public static readonly DependencyProperty BodyProperty =
            DependencyProperty.RegisterAttached("Body", typeof(string), typeof(WebBrowserUtility), new PropertyMetadata(OnBodyChanged));

        public static string GetBody(DependencyObject dependencyObject)
        {
            return (string)dependencyObject.GetValue(BodyProperty);
        }

        public static void SetBody(DependencyObject dependencyObject, string body)
        {
            dependencyObject.SetValue(BodyProperty, body);
        }

        private static void OnBodyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var webBrowser = (WebBrowser)d;
            string uri = e.NewValue as string;
            webBrowser.Source = new Uri(uri, UriKind.Absolute);    //This is my error line with message "Invalid URI: The format of the URI could not be determined."


            //If I put the "string" format directly in this code, it works properly and shows the PDF.
 //     webBrowser.Source = new Uri("file:///C:/Users/Documents/A.pdf", UriKind.Absolute);


        }
<WebBrowser local:WebBrowserUtility.Body="{Binding Path=Value}"/>



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>