Silverlight中,中文输入法的问题

diandian82 2012-03-27 08:17:33
问题描述:
1.新建一个Silverlight4 Navigation Application
2.在Home.xaml中加入tabcontrol和一些控件,如下


<controls:TabControl x:Name="tbC" Grid.Row="1" >
<controls:TabItem Header="基本信息">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="用户组名:" />
<TextBox Grid.Row="0" Grid.Column="1" Name="tbName" />
<CheckBox x:Name="cb" Grid.Row="1" Content="test" />
</Grid>
</controls:TabItem>
<controls:TabItem Header="客户">
<Grid Background="AliceBlue">
<ListBox x:Name="lstCustomers">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Name}" Tag="{Binding ID}" IsChecked="{Binding IsSelected, Mode=TwoWay}"></CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</controls:TabItem>
</controls:TabControl>


开始的时候一切正常,可以在tbName的Textbox中输入中文,但切换到第二个tab后,再切换回第一个tab,就再也无法在tbName中输入任何中文,输入法也打不开了,不知道什么原因。但我发现,如果在上面加入一个Checkbox,点击这个checkbox,然后再点击输入框,这样就又可以输入中文了,这到底是什么毛病啊?有人知道么?

我的系统是Windows7 Ultimate 64位 英文版,在使用Silverlight 4
...全文
688 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
aday 2012-05-20
  • 打赏
  • 举报
回复
呵呵,SL5的确没这个问题
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 的回复:]

最后升级到SL5解决了
[/Quote]

能够给出帖子的解答很好。


我早就在半年前用SL5了。
diandian82 2012-05-19
  • 打赏
  • 举报
回复
最后升级到SL5解决了
岁月无情_1 2012-05-07
  • 打赏
  • 举报
回复
不知道楼上说的对不对,不过以前貌似遇到过类似的问题,focus是有点问题,你确保你的输入控件外面没有套用busyindicator控件,还有Focus()方法貌似有时候不太好使
bloodish 2012-05-07
  • 打赏
  • 举报
回复
通过转移焦点可以解决这个问题,下面是实际项目中的一个辅助类,用于解决这个问题。
在Load事件中调用RegisterControl,
在Unload事件中调用UnregisterControl,


public static class IMEHooker
{
private static Dictionary<Control, Control> IMEControls { get; set; }

static IMEHooker()
{
IMEControls = new Dictionary<Control, Control>();
}

/// <summary>
///Register an input control and a focus shift control
///Call this method in load event
/// </summary>
/// <param name="input">the ctrl which will receive the IME input</param>
/// <param name="foucs">the ctrl which can receive focus</param>
public static void RegisterControl(Control input, Control focus)
{
//If ctrl in dictionary just return
if (IMEControls.ContainsKey(input)) return;

//add ctrl to dictionary
IMEControls[input] = focus;

//register got focus event
input.GotFocus += OnGotFocus;
}

//Inversed process of register control method
public static void UnregisterControl(Control input)
{
if (!IMEControls.ContainsKey(input)) return;

IMEControls.Remove(input);

input.GotFocus -= OnGotFocus;
}

static void OnGotFocus(object sender, RoutedEventArgs e)
{
Control input = sender as Control;
if (input != null)
{
Control focus;

if (IMEControls.TryGetValue(input, out focus))
{
//unregister the event to avoid the call over stack
input.GotFocus -= OnGotFocus;

//let's shift the focus to the predefined ctrl
focus.Focus();

//focus again, focus event will not be fired.
input.Focus();

//register got focus event again
input.GotFocus += (OnGotFocus);
}
}
}
}
taihongbo 2012-05-06
  • 打赏
  • 举报
回复
问题解决了吗?我想知道答案。
今天我也遇到这个问题。谢谢!
  • 打赏
  • 举报
回复
如果你粘贴中文进去,程序是不是会crash?
有这么一个bug,会在SL5 GDR1中fix掉。很快就要发布了。
livesw 2012-05-04
  • 打赏
  • 举报
回复
解决方法很简单,将软件升级至sl5即可
E次奥 2012-05-04
  • 打赏
  • 举报
回复
是不是切换Tab后,没有获得焦点啊。让Tab强制获得焦点。
諾临風 2012-04-25
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

引用 7 楼 的回复:

windowless = false 就可以了,我是这样搞的。


我已经设置了这个了,开始是可以输入中文,但切换一下tab,就无法再输入了。。。
[/Quote]
问题我需要层显示SL的上面啊。。。。我也遇到了,好烦的。。。
zxhxiaoyi51 2012-04-20
  • 打赏
  • 举报
回复
坐等答案 我也遇到了
diandian82 2012-04-07
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

windowless = false 就可以了,我是这样搞的。
[/Quote]

我已经设置了这个了,开始是可以输入中文,但切换一下tab,就无法再输入了。。。
grt 2012-04-03
  • 打赏
  • 举报
回复
windowless = false 就可以了,我是这样搞的。
diandian82 2012-04-02
  • 打赏
  • 举报
回复
咋弄????
diandian82 2012-03-29
  • 打赏
  • 举报
回复
没解决,有解决了的么?怎么没有个靠谱的答案
grt 2012-03-29
  • 打赏
  • 举报
回复
不是说把windowless = false 就可输中文了吗?
qiangheihei 2012-03-28
  • 打赏
  • 举报
回复
我也遇到这个问题了。。。楼主解决了没???
wwwljh 2012-03-27
  • 打赏
  • 举报
回复
问题源于前不久做的SL应用,开发是在SL4下开发的,由于完成后SL5也出来了,据说性能有较大提高,就把客户端升级到了SL5。经过简单的测试后,没发现什么异常。可是过了两天,客户打电话说:中文不能输入了,输入法切换后还是英文,或根本就切换不了。可开发机器上一切正常啊!

  程序用了自己写的控件,其中用到了Popup控件,Popup中的ListBox控件作为一个下拉列表供用户选择。 在win7上测试发现,当选中一项,Popup隐藏后,将焦点移到下一个TextBox控件,原来好好的输入法变为了这样:
  XP和2003下测试,只能发现语言栏变短了!并且不管用什么输入法都一样不能输入中文!

  Google搜索后发现,ContextMenu控件也有这样的问题,当菜单显示时,也会出现上面的现象!由此推断SL对输入法的控制是这样的:如果当前获得焦点的控件不能输入,就禁用中文输入法!

  于是将自定义控件中的Focus()语句注释掉,运行正常了,难道是Focus到了一个无效的控件上了!可是不知道SL4为什么正常呢?

  进一步修改代码:Popup隐藏后,再调用Focus(),这样输入法正常了!

  看来用Silverlight开发还是会遇到不少麻烦的。

http://www.silverlightchina.net/html/tips/2012/0111/13249.html
diandian82 2012-03-27
  • 打赏
  • 举报
回复
别老Copy别人的,这个我早看过了

8,737

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧