// /************************************************************************
// * @file         BrowserBehavior.cs
// * @author   Su Liang
// * @date       2023/04/14
// *
// * @copyright &copy Sicentury Inc.
// *
// * @brief
// *
// * @details
// *
// *
// * *****************************************************************************/

using System.Diagnostics;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace MECF.Framework.UI.Core.Behaviors
{
    public class BrowserBehavior
    {
        public static readonly DependencyProperty HtmlProperty = DependencyProperty.RegisterAttached(
            "Html", typeof(string), typeof(BrowserBehavior), new FrameworkPropertyMetadata(OnHtmlChanged));

        [AttachedPropertyBrowsableForType(typeof(WebBrowser))]
        public static string GetHtml(WebBrowser browser)
        {
            return (string)browser.GetValue(HtmlProperty);
        }

        public static void SetHtml(WebBrowser browser, string value)
        {
            browser.SetValue(HtmlProperty, value);
        }

        static void OnHtmlChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
        {
            var browser = dependencyObject as WebBrowser;
            var html = e.NewValue.ToString();
            Debug.WriteLine(html);
            browser?.NavigateToString(html);
        }
    }
}