private void drawingSurfacebg_Loaded(object sender, RoutedEventArgs e) { cb = new ONSCL_Callback(this); if (m_d3dBackground == null) { m_d3dBackground = new Direct3DInterop(gamefolder); //横屏 double deviceh = Math.Floor(Application.Current.Host.Content.ActualWidth * Application.Current.Host.Content.ScaleFactor / 100.0); double devicew = Math.Floor(Application.Current.Host.Content.ActualHeight * Application.Current.Host.Content.ScaleFactor / 100.0); double xamlh = Application.Current.Host.Content.ActualWidth; double xamlw = Application.Current.Host.Content.ActualHeight; switch (ONSCL_GameInfoPage.nsg.screentype) { case 1: m_d3dBackground.SetONSResolutionAndDisplayMode((int)deviceh * 4 / 3, (int)deviceh, 640, 480, 0xF); drawingSurfacebg.Width = 640; break; case 2: m_d3dBackground.SetONSResolutionAndDisplayMode((int)devicew, (int)devicew * 3 / 4, 800, 600, 0xFF); RenderArea.Margin = new Thickness(0, 0, 0, -200); drawingSurfacebg.Height = 600; drawingSurfacebg.VerticalAlignment = VerticalAlignment.Top; break; } m_d3dBackground.InitGlobalCallback(cb); // 设置窗口边界(以 dip 为单位) m_d3dBackground.WindowBounds = new Windows.Foundation.Size(xamlw, xamlh); // 设置本机分辨率(以像素为单位) m_d3dBackground.NativeResolution = new Windows.Foundation.Size(devicew, deviceh); // 将呈现分辨率设置为本机的最大分辨率 m_d3dBackground.RenderResolution = m_d3dBackground.NativeResolution; // 将本机组件挂钩到 DrawingSurfaceBackgroundGrid drawingSurfacebg.SetContentProvider(m_d3dBackground.CreateContentProvider()); drawingSurfacebg.SetManipulationHandler(m_d3dBackground); } }