博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
silverlight 不能输入中文问题
阅读量:7113 次
发布时间:2019-06-28

本文共 18033 字,大约阅读时间需要 60 分钟。

<param name="Windowless" value="true" />

将调用silverlight页面的这句删除掉应该就能解决问题了

1.将<param name="Windowless" value="true" />以上代码注释(删除)操作,虽然可以输入中文,但是silverlight嵌套html将会报错?想要解决silverlight嵌套html问题、silverlight无法输入中文问题,只能是换一种实现方法。具体操作如下

1.自定义用户控件HtmlHost.cs

1 using System;  2 using System.Net;  3 using System.Windows;  4 using System.Windows.Controls;  5 using System.Windows.Documents;  6 using System.Windows.Ink;  7 using System.Windows.Input;  8 using System.Windows.Media;  9 using System.Windows.Media.Animation; 10 using System.Windows.Shapes; 11 using System.Windows.Markup; 12 using System.Windows.Browser; 13 using System.Threading; 14  15 namespace HtmlInSilverlight 16 { 17     [ContentProperty("SourceHtml")] 18     public class HtmlHost : FrameworkElement 19     { 20         public static readonly DependencyProperty SourceHtmlProperty = DependencyProperty.Register("SourceHtml", typeof(string), typeof(HtmlHost), new PropertyMetadata(string.Empty, new PropertyChangedCallback(HtmlHost.SourceHtmlChanged))); 21         public static readonly DependencyProperty SourceUriProperty = DependencyProperty.Register("SourceUri", typeof(Uri), typeof(HtmlHost), new PropertyMetadata(null, new PropertyChangedCallback(HtmlHost.SourceUriChanged))); 22         private HtmlDocument _document; 23         private HtmlElement _iframe; 24         private EventHandler _documentready; 25         private bool x9794bc5afbd6d4a3; 26         private bool xe3e0019204361915; 27         private HtmlElement _div; 28  29         public event EventHandler DocumentReady 30         { 31             add 32             { 33                 EventHandler handler2; 34                 EventHandler handler = this._documentready; 35                 do 36                 { 37                     handler2 = handler; 38                     EventHandler handler3 = (EventHandler)Delegate.Combine(handler2, value); 39                     handler = Interlocked.CompareExchange
(ref this._documentready, handler3, handler2); 40 } 41 while (handler != handler2); 42 } 43 remove 44 { 45 EventHandler handler2; 46 EventHandler handler = this._documentready; 47 do 48 { 49 handler2 = handler; 50 EventHandler handler3 = (EventHandler)Delegate.Remove(handler2, value); 51 handler = Interlocked.CompareExchange
(ref this._documentready, handler3, handler2); 52 } 53 while (handler != handler2); 54 } 55 } 56 57 public HtmlHost() 58 { 59 base.Loaded += new RoutedEventHandler(this._Loaded); 60 base.SizeChanged += new SizeChangedEventHandler(this._SizeChanged); 61 base.LayoutUpdated += new EventHandler(this._LayoutUpdated); 62 } 63 64 protected virtual void OnDocumentReady(EventArgs e) 65 { 66 if (this._documentready != null) 67 { 68 this._documentready(this, e); 69 } 70 } 71 72 private void _Refresh() 73 { 74 Rect rect; 75 Size renderSize; 76 double num = 0; 77 double num2 = 0; 78 double num4 = 0; 79 if (this._div == null) 80 { 81 return; 82 } 83 goto Label_03E5; 84 Label_0010: 85 if (rect.Height > 0.0) 86 { 87 goto Label_0148; 88 } 89 Label_0025: 90 this._div.SetStyleAttribute("visibility", "hidden"); 91 this._div.SetStyleAttribute("display", "none"); 92 if ((((uint)num4) + ((uint)num)) >= 0) 93 { 94 goto Label_0219; 95 } 96 goto Label_0090; 97 Label_0069: 98 if (rect.Width <= 0.0) 99 {100 goto Label_0025;101 }102 if (((uint)num2) >= 0)103 {104 goto Label_0010;105 }106 Label_0090:107 if ((((uint)num) & 0) != 0)108 {109 goto Label_0069;110 }111 if ((((uint)num) + ((uint)num4)) >= 0)112 {113 goto Label_0010;114 }115 goto Label_0219;116 Label_0148:117 if (!this.xe3e0019204361915)118 {119 HtmlPage.Document.Body.AppendChild(this._div);120 this.xe3e0019204361915 = true;121 goto Label_0194;122 }123 Label_0153:124 this._div.SetStyleAttribute("visibility", "visible");125 this._div.SetStyleAttribute("display", "inline");126 if ((((uint)num) & 0) != 0)127 {128 goto Label_02A0;129 }130 Label_0194:131 num = rect.X;132 this._div.SetStyleAttribute("left", num.ToString() + "px");133 if ((((uint)num) + ((uint)num)) <= uint.MaxValue)134 {135 this._div.SetStyleAttribute("top", rect.Y.ToString() + "px");136 this._div.SetStyleAttribute("width", rect.Width.ToString() + "px");137 this._div.SetStyleAttribute("height", rect.Height.ToString() + "px");138 return;139 }140 if ((((uint)num2) + ((uint)num)) <= uint.MaxValue)141 {142 goto Label_0090;143 }144 Label_0219:145 if (((uint)num2) >= 0)146 {147 return;148 }149 goto Label_03E5;150 Label_02A0:151 if (renderSize.Width > 0.0)152 {153 Size size2 = base.RenderSize;154 if ((((uint)num4) + ((uint)num4)) <= uint.MaxValue)155 {156 if (0 != 0)157 {158 goto Label_0148;159 }160 while ((size2.Height > 0.0) && (base.Visibility == Visibility.Visible))161 {162 double num3 = 0;163 Point location = base.TransformToVisual(Application.Current.RootVisual).Transform(new Point(0.0, 0.0));164 rect = new Rect(location, base.RenderSize);165 HtmlElement element = this.xe90f25b5dbb13eeb();166 object property = element.GetProperty("offsetLeft");167 if (property is double)168 {169 rect.X += (double)property;170 }171 object obj3 = element.GetProperty("offsetTop");172 if (obj3 is double)173 {174 rect.Y += (double)obj3;175 break;176 }177 if ((((uint)num4) - ((uint)num3)) <= uint.MaxValue)178 {179 break;180 }181 if ((((uint)num3) & 0) != 0)182 {183 goto Label_0153;184 }185 }186 goto Label_0069;187 }188 }189 else190 {191 goto Label_0069;192 }193 Label_03A4: ;194 rect = new Rect(0.0, 0.0, 0.0, 0.0);195 renderSize = base.RenderSize;196 if ((((uint)num4) + ((uint)num)) <= uint.MaxValue)197 {198 }199 goto Label_02A0;200 Label_03E5:201 if (0 == 0)202 {203 if (!HtmlPage.IsEnabled)204 {205 return;206 }207 goto Label_03A4;208 }209 }210 211 private void _Loaded(object sender, RoutedEventArgs e)212 {213 HtmlElement element;214 if (this.x9794bc5afbd6d4a3)215 {216 return;217 }218 this.x9794bc5afbd6d4a3 = true;219 if (!HtmlPage.IsEnabled)220 {221 goto Label_0026;222 }223 this._div = HtmlPage.Document.CreateElement("div");224 this._div.SetAttribute("id", "div" + this.GetHashCode());225 this._div.SetStyleAttribute("position", "absolute");226 this._div.SetStyleAttribute("visibility", "collapsed");227 element = this.xe90f25b5dbb13eeb();228 element.AttachEvent("onmove", new EventHandler(this._Moved));229 goto Label_004A;230 Label_0010:231 if (!Application.Current.Host.Settings.Windowless)232 {233 //MessageBox.Show("Warning: The HtmlHost control should always be used with a windowless plugin. It cannot work reliably if this property is not specified.");234 }235 Label_0026:236 this.x8c7c45ccab715fbf();237 return;238 Label_0031:239 goto Label_0010;240 Label_004A:241 if (element != HtmlPage.Plugin)242 {243 goto Label_0065;244 }245 if (-2147483648 != 0)246 {247 goto Label_0010;248 }249 goto Label_0031;250 Label_0065:251 HtmlPage.Plugin.AttachEvent("onmove", new EventHandler(this._Moved));252 goto Label_0031;253 }254 255 private void IFrame_Loaded(object sender, EventArgs e)256 {257 HtmlWindow property = this._iframe.GetProperty("contentWindow") as HtmlWindow;258 do259 {260 HtmlDocument document;261 if (property != null)262 {263 document = property.GetProperty("document") as HtmlDocument;264 if ((document == null))265 {266 return;267 }268 }269 else270 {271 return;272 }273 this.Document = document;274 }275 while ((0 == 0) && (((0xff == 0) && (1 != 0)) || (0 != 0)));276 }277 278 private static void SourceUriChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)279 {280 ((HtmlHost)sender).x8c7c45ccab715fbf();281 }282 283 private void x8c7c45ccab715fbf()284 {285 if (!HtmlPage.IsEnabled)286 {287 return;288 }289 goto Label_0107;290 Label_000F:291 this._Refresh();292 if (0 == 0)293 {294 if (0 == 0)295 {296 return;297 }298 goto Label_0107;299 }300 goto Label_00E6;301 Label_0052:302 this._div.AppendChild(this.IFrame);303 this.IFrame.SetAttribute("src", this.SourceUri.ToString());304 goto Label_000F;305 Label_0080:306 this._div.RemoveChild((HtmlElement)this._div.Children[0]);307 Label_00AB:308 if (this._div.Children.Count > 0)309 {310 goto Label_0080;311 }312 if (this.SourceUri == null)313 {314 this._div.SetStyleAttribute("overflow", "auto");315 this.SetDivHtml(this._div, this.SourceHtml);316 if (0 == 0)317 {318 goto Label_000F;319 }320 }321 else322 {323 this._div.SetStyleAttribute("overflow", "hidden");324 goto Label_0052;325 }326 Label_00E6:327 if ((0x7fffffff != 0) && (0x7fffffff != 0))328 {329 goto Label_0080;330 }331 goto Label_0052;332 Label_0107:333 if (!this.x9794bc5afbd6d4a3)334 {335 return;336 }337 goto Label_00AB;338 }339 340 private void _LayoutUpdated(object sender, EventArgs e)341 {342 this._Refresh();343 }344 345 private void _Moved(object sender, EventArgs e)346 {347 this._Refresh();348 }349 350 private HtmlElement xe90f25b5dbb13eeb()351 {352 HtmlElement element2;353 HtmlElement plugin = HtmlPage.Plugin;354 if (HtmlPage.Plugin.Parent.TagName.ToLower() == "div")355 {356 if (HtmlPage.Plugin.Parent.Children.Count == 1)357 {358 return HtmlPage.Plugin.Parent;359 }360 if (HtmlPage.Plugin.Parent.Children.Count == 2)361 {362 if (HtmlPage.Plugin.Parent.Children[0] != HtmlPage.Plugin)363 {364 return plugin;365 }366 element2 = HtmlPage.Plugin.Parent.Children[1] as HtmlElement;367 if (element2 == null)368 {369 return plugin;370 }371 if (!(element2.TagName.ToLower() == "iframe"))372 {373 return plugin;374 }375 return HtmlPage.Plugin.Parent;376 }377 return plugin;378 }379 return plugin;380 }381 382 private void _SizeChanged(object sender, SizeChangedEventArgs e)383 {384 this._Refresh();385 }386 387 private void SetDivHtml(HtmlElement _div, string html)388 {389 if (HtmlPage.BrowserInformation.Name == "Netscape")390 {391 _div.SetProperty("innerHTML", html);392 }393 else394 {395 _div.SetAttribute("innerHTML", html);396 }397 }398 399 private static void SourceHtmlChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)400 {401 ((HtmlHost)sender).x8c7c45ccab715fbf();402 }403 404 public HtmlDocument Document405 {406 get407 {408 return this._document;409 }410 private set411 {412 if (value != this._document)413 {414 this._document = value;415 if (this._document == null)416 {417 return;418 }419 this.OnDocumentReady(EventArgs.Empty);420 }421 }422 }423 424 public HtmlWindow Window425 {426 get427 {428 HtmlWindow property = this._iframe.GetProperty("contentWindow") as HtmlWindow;429 return property;430 }431 }432 433 public string SourceHtml434 {435 get436 {437 return (string)base.GetValue(SourceHtmlProperty);438 }439 set440 {441 base.SetValue(SourceHtmlProperty, value);442 }443 }444 445 public Uri SourceUri446 {447 get448 {449 return (Uri)base.GetValue(SourceUriProperty);450 }451 set452 {453 base.SetValue(SourceUriProperty, value);454 }455 }456 457 private HtmlElement IFrame458 {459 get460 {461 if (this._iframe != null)462 {463 return this._iframe;464 }465 if (HtmlPage.IsEnabled)466 {467 this._iframe = HtmlPage.Document.CreateElement("iframe");468 this._iframe.SetStyleAttribute("position", "absolute");469 this._iframe.SetStyleAttribute("width", "100%");470 this._iframe.SetStyleAttribute("height", "100%");471 this._iframe.SetStyleAttribute("border", "0px");472 this._iframe.SetAttribute("border", "0");473 this._iframe.SetAttribute("frameBorder", "0");474 this._iframe.AttachEvent("onload", new EventHandler(this.IFrame_Loaded));475 HtmlPage.Document.Body.AppendChild(this._iframe);476 }477 return this._iframe;478 }479 }480 }481 }
View Code

2.将自定义用户控件引用到页面中MainPage.xaml

1 
9 10
11
12
13
14
15
16
17 18
19
View Code

这样就ok了。

注意:将.aspx中<param name="Windowless" value="true" />这段话注释或者删除。

 3.此做法可能还会出现异常

4.最终做法

Label_0153:            this._div.SetStyleAttribute("visibility", "visible");            this._div.SetStyleAttribute("display", "inline");            this._div.SetStyleAttribute("background", "White");            if ((((uint)num) & 0) != 0)            {                goto Label_02A0;            }

将这段代码替换HtmlHost.cs中的代码,与HtmlHost.cs类库不同的是 多加了

this._div.SetStyleAttribute("background", "White"); 具体什么原因,我也不清楚

转载于:https://www.cnblogs.com/zxbzl/p/3934450.html

你可能感兴趣的文章
阿里云全球首批 MVP 赵玮专访 - 爱运动的女研究员
查看>>
《Excel 职场手册:260招菜鸟变达人》一第 30 招 查找重复值或唯一值
查看>>
决定将代码开源之前要确定的四个问题
查看>>
Java多线程CyclicBarrier学习
查看>>
厌倦了编程书?来试试这3种提高编程技能的有趣方法吧
查看>>
《教孩子学编程(Python语言版)》——2.4 添加颜色
查看>>
并发工具类(四)两个线程进行数据交换的Exchanger
查看>>
《精通Spring MVC 4》——1.4 命令行方式简介
查看>>
Ceph分布式存储实战1.2 Ceph的功能组件
查看>>
《贝叶斯思维:统计建模的Python学习法》一2.5 封装框架
查看>>
《操作系统真象还原》——0.20 BIOS中断、DOS中断、Linux中断的区别
查看>>
爱的初体验!第二弹!多图! —— GNOME 3.10/Arch Linux
查看>>
《C++覆辙录》——1.12:嘴上无毛,办事不牢
查看>>
《嵌入式Linux软硬件开发详解——基于S5PV210处理器》——2.4 DM9000A以太网控制器...
查看>>
《TensorFlow技术解析与实战》——3.4 小结
查看>>
《Python高性能编程》——2.11 用dowser实时画出变量的实例
查看>>
《软件测试工程师面试秘籍》—第1章1.2节第一印象
查看>>
演讲实录丨丨Young-Jo Cho 基于网络的机器智能机器人技术的发展
查看>>
独家 | 第十届中国R会议(北京)
查看>>
《JavaScript启示录》——1.13 如何存储或复制复杂值
查看>>