Exemplo n.º 1
0
        /// <summary>
        /// Convert the framework element to a Window Handle so it can be serialized.
        /// </summary>
        /// <param name="frameworkElement">The framework element to convert to a Window Handle.</param>
        /// <returns>The Window Handle that is hosting the framework element.</returns>
        static long CreateWindowHandle(Visual frameworkElement)
        {
            // ReSharper disable InconsistentNaming
            const int WS_VISIBLE = 0x10000000;
            // ReSharper restore InconsistentNaming

            var parameters = new HwndSourceParameters(String.Format("NewWindowHost{0}", Guid.NewGuid()), 1, 1);

            parameters.WindowStyle &= ~WS_VISIBLE;

            var intPtr = new HwndSource(parameters)
            {
                RootVisual = frameworkElement
            }.Handle;

            return(intPtr.ToInt64());
        }