Silverlight 中缺少的某些 WPF 功能的解决方法 [英] Workaround for some WPF features that are missing in Silverlight

查看:23
本文介绍了Silverlight 中缺少的某些 WPF 功能的解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 WPF 应用程序移植到 Silverlight 2,并且遇到了目前 SL 中缺少的几个 WPF 功能.任何人都可以帮助我解决等效问题或建议解决方法.

I’m porting a WPF app to silverlight 2, and have come across several WPF features which are presently missing from SL. Could anyone help me with equivalents or suggest workarounds.

  1. 我想处理嵌入在列表框中的文本框的点击和双击.WPF 实现在列表框控件上使用 PreviewMouseLeftButtonDown/Up.这在silverlight中如何实现,silverlight中似乎缺少PreviewMouseLeftButtonDown/Up.

  1. I want to handle clicks and double clicks on a textbox embedded in a list box. The WPF implementation uses PreviewMouseLeftButtonDown/Up on a listbox control. How can this be done in silverlight, it seems that PreviewMouseLeftButtonDown/Up are missing in silverlight.

我想处理嵌入在列表框中的文本框上的按钮按下(F2/Delete).WPF 实现在作为项目嵌入列表框中的文本框控件上使用 PreviewKeyDown.Silverlight 中似乎缺少 PreviewKeyDown.KeyDown 事件处理程序似乎没有被调用.

I want to handle button presses (F2/Delete) on a textbox embedded in a list box. The WPF implementation uses PreviewKeyDown on a textbox control which embedded as an item in a listbox. It seems that PreviewKeyDown is missing in silverlight. The KeyDown event handler does not seem to get invoked.

我想根据一些自定义附加属性的值更改文本框的一些外观属性.WPF 实现使用 DataTrigger 来执行此操作.这怎么能在silverlight中完成.Silverlight 中似乎缺少 DataTriggers.

I want to change some appearance properties of a textbox depending on the value of some custom attached properties. The WPF implementation uses a DataTrigger to do this. How can this be done in silverlight. It seems that DataTriggers are missing in silverlight.

我想根据包含文本框的列表框的实际宽度更改文本框的宽度.WPF 实现使用 RelativeSource 绑定.什么是 Silverlight 等价物或解决方法.

I want to change the width of a text box depending on the Actual Width of the listbox in which the text box is contained. The WPF implementation uses RelativeSource binding. What is the silverlight equivalent, or workaround for this.

推荐答案

对于第 1 项和第 2 项,访问这些输入事件的最佳方法是创建一个从内置 TextBox 派生的自定义 TextBox.然后您可以向下覆盖 OnKeyDown 和 OnMouseLeftButton.从那里你可以调用必要的代码,或者触发一个新的事件.例如:

For item 1 and 2, the best way to get access to these input events is to create a custom TextBox deriving from the built in TextBox. Then you can override the OnKeyDown and OnMouseLeftButton down. From there you can either call the necessary code, or fire a new event. e.g.:

public class MyTextBox : TextBox
{
    public event MouseButtonEventHandler MySpecialMouseLeftButtonDown;

    protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
    {
        if (MySpecialMouseLeftButtonDown != null)
        {
            MySpecialMouseLeftButtonDown(this, e);
        }
        base.OnMouseLeftButtonDown(e);
    }
}

与 OnKeyDown 类似.

Similarly with OnKeyDown.

这篇关于Silverlight 中缺少的某些 WPF 功能的解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆