silverlight 不能输入中文问题
<param name="Windowless" value="true" />
将调用silverlight页面的这句删除掉应该就能解决问题了
1.将<param name="Windowless" value="true" />以上代码注释(删除)操作,虽然可以输入中文,但是silverlight嵌套html将会报错?想要解决silverlight嵌套html问题、silverlight无法输入中文问题,只能是换一种实现方法。具体操作如下
1.自定义用户控件HtmlHost.cs
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Markup;
using System.Windows.Browser;
using System.Threading; namespace HtmlInSilverlight
{
[ContentProperty("SourceHtml")]
public class HtmlHost : FrameworkElement
{
public static readonly DependencyProperty SourceHtmlProperty = DependencyProperty.Register("SourceHtml", typeof(string), typeof(HtmlHost), new PropertyMetadata(string.Empty, new PropertyChangedCallback(HtmlHost.SourceHtmlChanged)));
public static readonly DependencyProperty SourceUriProperty = DependencyProperty.Register("SourceUri", typeof(Uri), typeof(HtmlHost), new PropertyMetadata(null, new PropertyChangedCallback(HtmlHost.SourceUriChanged)));
private HtmlDocument _document;
private HtmlElement _iframe;
private EventHandler _documentready;
private bool x9794bc5afbd6d4a3;
private bool xe3e0019204361915;
private HtmlElement _div; public event EventHandler DocumentReady
{
add
{
EventHandler handler2;
EventHandler handler = this._documentready;
do
{
handler2 = handler;
EventHandler handler3 = (EventHandler)Delegate.Combine(handler2, value);
handler = Interlocked.CompareExchange<EventHandler>(ref this._documentready, handler3, handler2);
}
while (handler != handler2);
}
remove
{
EventHandler handler2;
EventHandler handler = this._documentready;
do
{
handler2 = handler;
EventHandler handler3 = (EventHandler)Delegate.Remove(handler2, value);
handler = Interlocked.CompareExchange<EventHandler>(ref this._documentready, handler3, handler2);
}
while (handler != handler2);
}
} public HtmlHost()
{
base.Loaded += new RoutedEventHandler(this._Loaded);
base.SizeChanged += new SizeChangedEventHandler(this._SizeChanged);
base.LayoutUpdated += new EventHandler(this._LayoutUpdated);
} protected virtual void OnDocumentReady(EventArgs e)
{
if (this._documentready != null)
{
this._documentready(this, e);
}
} private void _Refresh()
{
Rect rect;
Size renderSize;
double num = ;
double num2 = ;
double num4 = ;
if (this._div == null)
{
return;
}
goto Label_03E5;
Label_0010:
if (rect.Height > 0.0)
{
goto Label_0148;
}
Label_0025:
this._div.SetStyleAttribute("visibility", "hidden");
this._div.SetStyleAttribute("display", "none");
if ((((uint)num4) + ((uint)num)) >= )
{
goto Label_0219;
}
goto Label_0090;
Label_0069:
if (rect.Width <= 0.0)
{
goto Label_0025;
}
if (((uint)num2) >= )
{
goto Label_0010;
}
Label_0090:
if ((((uint)num) & ) != )
{
goto Label_0069;
}
if ((((uint)num) + ((uint)num4)) >= )
{
goto Label_0010;
}
goto Label_0219;
Label_0148:
if (!this.xe3e0019204361915)
{
HtmlPage.Document.Body.AppendChild(this._div);
this.xe3e0019204361915 = true;
goto Label_0194;
}
Label_0153:
this._div.SetStyleAttribute("visibility", "visible");
this._div.SetStyleAttribute("display", "inline");
if ((((uint)num) & ) != )
{
goto Label_02A0;
}
Label_0194:
num = rect.X;
this._div.SetStyleAttribute("left", num.ToString() + "px");
if ((((uint)num) + ((uint)num)) <= uint.MaxValue)
{
this._div.SetStyleAttribute("top", rect.Y.ToString() + "px");
this._div.SetStyleAttribute("width", rect.Width.ToString() + "px");
this._div.SetStyleAttribute("height", rect.Height.ToString() + "px");
return;
}
if ((((uint)num2) + ((uint)num)) <= uint.MaxValue)
{
goto Label_0090;
}
Label_0219:
if (((uint)num2) >= )
{
return;
}
goto Label_03E5;
Label_02A0:
if (renderSize.Width > 0.0)
{
Size size2 = base.RenderSize;
if ((((uint)num4) + ((uint)num4)) <= uint.MaxValue)
{
if ( != )
{
goto Label_0148;
}
while ((size2.Height > 0.0) && (base.Visibility == Visibility.Visible))
{
double num3 = ;
Point location = base.TransformToVisual(Application.Current.RootVisual).Transform(new Point(0.0, 0.0));
rect = new Rect(location, base.RenderSize);
HtmlElement element = this.xe90f25b5dbb13eeb();
object property = element.GetProperty("offsetLeft");
if (property is double)
{
rect.X += (double)property;
}
object obj3 = element.GetProperty("offsetTop");
if (obj3 is double)
{
rect.Y += (double)obj3;
break;
}
if ((((uint)num4) - ((uint)num3)) <= uint.MaxValue)
{
break;
}
if ((((uint)num3) & ) != )
{
goto Label_0153;
}
}
goto Label_0069;
}
}
else
{
goto Label_0069;
}
Label_03A4: ;
rect = new Rect(0.0, 0.0, 0.0, 0.0);
renderSize = base.RenderSize;
if ((((uint)num4) + ((uint)num)) <= uint.MaxValue)
{
}
goto Label_02A0;
Label_03E5:
if ( == )
{
if (!HtmlPage.IsEnabled)
{
return;
}
goto Label_03A4;
}
} private void _Loaded(object sender, RoutedEventArgs e)
{
HtmlElement element;
if (this.x9794bc5afbd6d4a3)
{
return;
}
this.x9794bc5afbd6d4a3 = true;
if (!HtmlPage.IsEnabled)
{
goto Label_0026;
}
this._div = HtmlPage.Document.CreateElement("div");
this._div.SetAttribute("id", "div" + this.GetHashCode());
this._div.SetStyleAttribute("position", "absolute");
this._div.SetStyleAttribute("visibility", "collapsed");
element = this.xe90f25b5dbb13eeb();
element.AttachEvent("onmove", new EventHandler(this._Moved));
goto Label_004A;
Label_0010:
if (!Application.Current.Host.Settings.Windowless)
{
//MessageBox.Show("Warning: The HtmlHost control should always be used with a windowless plugin. It cannot work reliably if this property is not specified.");
}
Label_0026:
this.x8c7c45ccab715fbf();
return;
Label_0031:
goto Label_0010;
Label_004A:
if (element != HtmlPage.Plugin)
{
goto Label_0065;
}
if (- != )
{
goto Label_0010;
}
goto Label_0031;
Label_0065:
HtmlPage.Plugin.AttachEvent("onmove", new EventHandler(this._Moved));
goto Label_0031;
} private void IFrame_Loaded(object sender, EventArgs e)
{
HtmlWindow property = this._iframe.GetProperty("contentWindow") as HtmlWindow;
do
{
HtmlDocument document;
if (property != null)
{
document = property.GetProperty("document") as HtmlDocument;
if ((document == null))
{
return;
}
}
else
{
return;
}
this.Document = document;
}
while (( == ) && (((0xff == ) && ( != )) || ( != )));
} private static void SourceUriChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
((HtmlHost)sender).x8c7c45ccab715fbf();
} private void x8c7c45ccab715fbf()
{
if (!HtmlPage.IsEnabled)
{
return;
}
goto Label_0107;
Label_000F:
this._Refresh();
if ( == )
{
if ( == )
{
return;
}
goto Label_0107;
}
goto Label_00E6;
Label_0052:
this._div.AppendChild(this.IFrame);
this.IFrame.SetAttribute("src", this.SourceUri.ToString());
goto Label_000F;
Label_0080:
this._div.RemoveChild((HtmlElement)this._div.Children[]);
Label_00AB:
if (this._div.Children.Count > )
{
goto Label_0080;
}
if (this.SourceUri == null)
{
this._div.SetStyleAttribute("overflow", "auto");
this.SetDivHtml(this._div, this.SourceHtml);
if ( == )
{
goto Label_000F;
}
}
else
{
this._div.SetStyleAttribute("overflow", "hidden");
goto Label_0052;
}
Label_00E6:
if ((0x7fffffff != ) && (0x7fffffff != ))
{
goto Label_0080;
}
goto Label_0052;
Label_0107:
if (!this.x9794bc5afbd6d4a3)
{
return;
}
goto Label_00AB;
} private void _LayoutUpdated(object sender, EventArgs e)
{
this._Refresh();
} private void _Moved(object sender, EventArgs e)
{
this._Refresh();
} private HtmlElement xe90f25b5dbb13eeb()
{
HtmlElement element2;
HtmlElement plugin = HtmlPage.Plugin;
if (HtmlPage.Plugin.Parent.TagName.ToLower() == "div")
{
if (HtmlPage.Plugin.Parent.Children.Count == )
{
return HtmlPage.Plugin.Parent;
}
if (HtmlPage.Plugin.Parent.Children.Count == )
{
if (HtmlPage.Plugin.Parent.Children[] != HtmlPage.Plugin)
{
return plugin;
}
element2 = HtmlPage.Plugin.Parent.Children[] as HtmlElement;
if (element2 == null)
{
return plugin;
}
if (!(element2.TagName.ToLower() == "iframe"))
{
return plugin;
}
return HtmlPage.Plugin.Parent;
}
return plugin;
}
return plugin;
} private void _SizeChanged(object sender, SizeChangedEventArgs e)
{
this._Refresh();
} private void SetDivHtml(HtmlElement _div, string html)
{
if (HtmlPage.BrowserInformation.Name == "Netscape")
{
_div.SetProperty("innerHTML", html);
}
else
{
_div.SetAttribute("innerHTML", html);
}
} private static void SourceHtmlChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
((HtmlHost)sender).x8c7c45ccab715fbf();
} public HtmlDocument Document
{
get
{
return this._document;
}
private set
{
if (value != this._document)
{
this._document = value;
if (this._document == null)
{
return;
}
this.OnDocumentReady(EventArgs.Empty);
}
}
} public HtmlWindow Window
{
get
{
HtmlWindow property = this._iframe.GetProperty("contentWindow") as HtmlWindow;
return property;
}
} public string SourceHtml
{
get
{
return (string)base.GetValue(SourceHtmlProperty);
}
set
{
base.SetValue(SourceHtmlProperty, value);
}
} public Uri SourceUri
{
get
{
return (Uri)base.GetValue(SourceUriProperty);
}
set
{
base.SetValue(SourceUriProperty, value);
}
} private HtmlElement IFrame
{
get
{
if (this._iframe != null)
{
return this._iframe;
}
if (HtmlPage.IsEnabled)
{
this._iframe = HtmlPage.Document.CreateElement("iframe"); this._iframe.SetStyleAttribute("position", "absolute");
this._iframe.SetStyleAttribute("width", "100%");
this._iframe.SetStyleAttribute("height", "100%");
this._iframe.SetStyleAttribute("border", "0px");
this._iframe.SetAttribute("border", "");
this._iframe.SetAttribute("frameBorder", "");
this._iframe.AttachEvent("onload", new EventHandler(this.IFrame_Loaded));
HtmlPage.Document.Body.AppendChild(this._iframe);
}
return this._iframe;
}
}
}
}
2.将自定义用户控件引用到页面中MainPage.xaml
<UserControl x:Class="HtmlInSilverlight.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:Html="clr-namespace:HtmlInSilverlight"
d:DesignHeight="" d:DesignWidth=""> <Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height=""></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBox Text="" Grid.Row=""></TextBox>
<Html:HtmlHost Grid.Row="" x:Name="htmlControl" SourceUri="http://hao.360.cn"></Html:HtmlHost> </Grid>
</UserControl>
这样就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) & ) != )
{
goto Label_02A0;
}
将这段代码替换HtmlHost.cs中的代码,与HtmlHost.cs类库不同的是 多加了
this._div.SetStyleAttribute("background", "White");
具体什么原因,我也不清楚
silverlight 不能输入中文问题的更多相关文章
- Debain下解决sublime无法输入中文
sublime安装的方法在此不做过多介绍,网上有很多中教程的方式.本文描述在已经安装sublime的前提下如何输入中文. 1.保存下面的代码到文件sublime_imfix.c(位于~目录) #inc ...
- xshell不能输入中文,显示为??
不知不觉间发现自己使用xshell的时候不能输入中文了,输入的中文会变成"??",开始以为是编码问题,看了一下编码设置后发现没有任何问题,而且显示中文没有出现乱码问题,只是在输入的 ...
- js控制文本框只能输入中文、英文、数字与指定特殊符号.
先在'' 里输入 onkeyup="value=value.replace(/[^\X]/g,'')" 然后在(/[\X]/g,'')里的 X换成你想输入的代码就可以了, 中文u4 ...
- sublime_text_2 ubuntu下无法输入中文 解决方法
参考资料:http://my.oschina.net/wugaoxing/blog/121281 环境配置:ubuntu 14.10 1.保存下述代码为 sublime_imfix.c 文件 /* s ...
- 允许Sublime编辑器在Ubuntu上输入中文
Sublime Text是一款功能非常强大的轻量级代码编辑器,有关功能介绍和使用可以看我另一篇文章的描述http://www.cnblogs.com/jaxu/p/5037547.html 不过,在U ...
- PhpStorm 2016.3 For Mac 重大里程碑更新 -- 终于解决了不能输入中文标点符号的重大bug
PhpStorm 2016.3 For Mac 重大里程碑更新 1.[终于解决了]不能输入中文标点符号的重大bug,如 逗号“,”.“.”: 2.可以在一个窗体中,同时打开多个项目: 3.其他... ...
- 关于Qt creator 无法使用fcitx输入中文的问题折腾
环境: 系统ubuntu16.04amd64,qt5.4.2 安装完qt5.4后,在编写代码时,发现无法输入中文,离开qt creator 就立刻正常.原因似乎是qt对fcitx支持. 解决方法我是参 ...
- Ubuntu下Sublime Text 3解决无法输入中文的方法
Ubuntu下Sublime Text 3解决无法输入中文的方法_百度经验http://jingyan.baidu.com/article/f3ad7d0ff8731609c3345b3b.html ...
- (js) 输入框只能输入中文、英文、数字、@符号和.符号
只能输入中文.英文.数字.@符号和.符号<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z0 ...
随机推荐
- [ActionScript 3.0] AS3 3D星形贴图
package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.MovieCl ...
- eclipse快速收缩展开代码
快速折叠所有代码和展开所有代码都是CTRL+SHIFT+/
- Bootstrap配套的js框架
求几个搭配bootstrap的js框架.实现如表单验证,文件多传下载等等 Bootstrap File Input文件选择控件: PNotify通知插件: ClockPicker时间拾取器: Boot ...
- Windows server 2008 下iis7 架设ftp服务器
架设了一天的ftp服务器,终于搞定了. 按着windows server 2003的思路在windows server 2008把ftp设置好后,登录过程老是出现:530 User cannot lo ...
- (easy)LeetCode 217.Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- 百度之星IP聚合(水题map&字符处理)
虽然题目停水的,但是好像字符处理运用的还比较合适 Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊 ...
- springMVC spring hibernate pom.xml备份
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- HTTP与HttpServlet
(1).HTTP协议 Web浏览器和服务器通过HTTP协议在Internet上发送和接收消息.HTTP是一种基于请求/响应模式的协议.客户端发送一个请求,服务器端返回对该请求响应. . (2).HTT ...
- 翻译:深入 AngularUI Router
原文地址:http://www.ng-newsletter.com/posts/angular-ui-router.html ui-router: https://angular-ui.github. ...
- Bootstrap 3 How-To #2 标题,链接与按钮
这个系列的要点来自一本名为 Twitter Bootstrap Web Development How-to 的书,但是,这本书的内容是基于以前版本的,与最新的 3.0 并不一致. 为了方便学习和使用 ...