WebBrowser veya WPF denetimi, CustomTaskPane denetimi içinde barındırıldıysa, Office uygulamasında içeriği düzgün görüntüley çalışmıyor
Özgün KB numarası: 4490421
Belirtiler
Bazı durumlarda, denetim CustomTaskPane denetiminde veya FormRegion içinde barındırıldıysa, WebBrowser veya WPF denetim içeriği Microsoft Office uygulamasında görüntülenmeebilir veya Outlook çalışmayabilir.
Neden
Bu sorunlara, ana bilgisayar uygulamasının denetimleriniz içinde işlenen HTML öğelerine odaklanmayı geri döndüremiyor olması veya Microsoft Office çözüm makalenizin içindeki Yüksek DPI ve DPI ölçeklendirmesini işleme makalesinde belirtilen Microsoft Office çözüm çözümlerinin yüksek DPI ölçeklendirmesi tarafından belirtilemesi neden olabilir.
1. Geçici Çözüm: Yüksek DPI ve DPI ölçeklendirmesi ile ilgili sorun
Aşağıda gösterildiği NativeImports gibi kodunuz için bir sınıf ekleyin ve yönteme aşağıdaki satırı ThisAddIn_Startup ekleyin:
NativeImports.SetThreadDpiHostingBehavior(NativeImports.DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_MIXED);
// ThisAddIn.cs
namespace TaskPaneWorkaround
{
public partial class ThisAddIn
{
private MyUserControl myUserControl1;
private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// Workaround for the rendering issues to do with DPI
NativeImports.SetThreadDpiHostingBehavior(NativeImports.DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_MIXED);
myUserControl1 = new MyUserControl();
myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1, "My Task Pane");
myCustomTaskPane.Visible = true;
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
// NativeImports.cs
namespace TaskPaneWorkaround
{
class NativeImports
{
internal enum DPI_HOSTING_BEHAVIOR
{
DPI_HOSTING_BEHAVIOR_INVALID = -1,
DPI_HOSTING_BEHAVIOR_DEFAULT = 0,
DPI_HOSTING_BEHAVIOR_MIXED = 1
};
[DllImport("user32.dll")]
internal static extern DPI_HOSTING_BEHAVIOR SetThreadDpiHostingBehavior(DPI_HOSTING_BEHAVIOR value);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
}
}
2. Geçici Çözüm: Ana bilgisayar uygulamasının odaklanmayı geri dönmesi sorunu
CustomTaskPane ile gerçek WebBrowser veya WPF denetimi arasına bir ara form ekleyin.
Uygulamaya özel görev bölmesi ekleme hakkında daha fazla bilgi için bkz. Uygulamaya özel görev bölmesi ekleme.
WPF işleme sorunları için, geçici çözüm Kılavuzda açıklandığı gibi bir WindowsForm içinde bir WPF UserControl barındırmadan oluşur: Windows Forms'da 3B WPF BileşikDenetimi barındırma.
Bu geçici çözümü uygulayan Kullanıcı Denetimim adlı bir kullanıcı denetimi örneği:
Eklentinize MyUserControl adlı bir UserControl ekleyin.
UserControl'inizin kaynak kodunu değiştirebilir ve aşağıdaki örnekte Paint Load, Paint ve Resize olay işleyicilerini bildirebilirsiniz.
Projenize bir WindowsForm formu ekleyin. Geçici Çözüm Olarak Ad girinForm ve Load olay işleyicisini bildirin.
Aşağıdaki örnekte gösterilen WebBrowser denetiminizi Geçici Çözüm Formuna ekleyin.
CustomTaskPane oluşturun ve MyUserControl'in bir örneğini ekleyin.
// ThisAddIn.cs namespace TaskPaneWorkaround { public partial class ThisAddIn { private MyUserControl myUserControl1; private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane; private void ThisAddIn_Startup(object sender, System.EventArgs e) { myUserControl1 = new MyUserControl(); myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1, "My Task Pane"); myCustomTaskPane.Visible = true; } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { } #region VSTO generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } #endregion } } // MyUserControl.cs using System; using System.Windows.Forms; using System.Runtime.InteropServices; namespace TaskPaneWorkaround { public partial class MyUserControl : UserControl { bool isformdisplayed = false; WorkaroundForm workaroundForm; [DllImport("user32.dll", SetLastError = true)] private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); public MyUserControl() { this.SuspendLayout(); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Name = "MyUserControl"; this.Paint += new System.Windows.Forms.PaintEventHandler(this.MyUserControl_Paint); this.Resize += new System.EventHandler(this.MyUserControl_Resize); this.ResumeLayout(false); this.Paint += MyUserControl_Paint; this.Resize += MyUserControl_Resize; } private void MyUserControl_Load(object sender, System.EventArgs e) { this.Paint += MyUserControl_Paint; } private void MyUserControl_Paint(object sender, PaintEventArgs e) { if (!isformdisplayed) { this.SuspendLayout(); workaroundForm = new WorkaroundForm(); SetParent(workaroundForm.Handle, this.Handle); workaroundForm.Dock = DockStyle.Fill; workaroundForm.Width = Width; workaroundForm.Height = Height; workaroundForm.Show(); isformdisplayed = true; this.ResumeLayout(); } } private void MyUserControl_Resize(object sender, EventArgs e) { if (isformdisplayed) { workaroundForm.Width = this.Width; workaroundForm.Height = this.Height; } } } } //WorkaroundForm.cs using System; using System.Drawing; using System.Windows.Forms; namespace TaskPaneWorkaround { public partial class WorkaroundForm : Form { public WorkaroundForm() { this.SuspendLayout(); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(509, 602); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.WorkaroundForm_Load); this.ResumeLayout(false); } private void WorkaroundForm_Load(object sender, EventArgs e) { this.SuspendLayout(); this.Location = new Point(0, 0); this.Dock = DockStyle.Fill; this.FormBorderStyle = FormBorderStyle.None; WebBrowser webBrowser = new WebBrowser(); this.Controls.Add(webBrowser); webBrowser.Location = new Point(0, 0); webBrowser.Dock = DockStyle.Fill; this.ResumeLayout(); webBrowser.Focus(); webBrowser.Navigate(new System.Uri("https://bing.com")); } } }
Daha fazla bilgi
WebBrowser ve WPF denetimi işleme sorunlarının çoğu, düzeltmeler ile ele alındı. Öte yandan, içerik doğru işlenmiyorsa, herhangi bir sorun oluşursa, odak denetim içinde işlenen HTML öğelerine döndürülz veya bazı tuş bileşimleri beklendiği gibi çalışmıyorsa, yukarıda açıklanan geçici çözümleri göz önünde bulundurabilirsiniz.
Bu makalede geçici çözümlerin yer alan bir kod örneği GitHub.