Windows Phone 8用户控件的VisibleChanged事件在哪里? [英] Where is the VisibleChanged event for a Windows Phone 8 user control?
问题描述
我在MSDN页面上找到了一个VisibleChanged事件的多个引用,指出它是针对Windows Phone 8平台的。但是,当我尝试通过Intellisense访问我正在构建的顶级用户控件(使用this关键字)或LayoutRoot网格时,我看不到它。我通过对象浏览器进行了全面搜索,我也看不到任何东西。它在哪里?当用户控件可见时,我需要执行某些
I've found more than one reference to a VisibleChanged event on MSDN pages that state it is for the Windows Phone 8 platform. However, when I try to access it via Intellisense for either the top level user control I'm building (using the "this" keyword), or for the LayoutRoot grid, I don't see it. I did a full search via the Object Browser and I don't see anything there either. Where is it? I need to perform certain task only when the user control is visible, and I need them to stop when it is not.
http:// msdn。 microsoft.com/en-us/library/system.windows.forms.control.visiblechanged(v=vs.110).aspx
推荐答案
您的参考是指Windows Windows应用程序,而不是Windows Phone。您在Windows Phone上询问的属性是可见性
(不是可见
),所以你应该寻找 VisibilityChanged
- 但是不存在。
Your reference refers to Windows Form apps for Windows, not Windows Phone. The property you're asking about on Windows Phone is Visibility
(not Visible
) so you should be looking for VisibilityChanged
--but that does not exist.
然而,您可以通过将您自己的控件进行子类化来创建自己的想要事件然后使用你的新控件。例如:
You could, however, create your own by subclassing the control for which you want the event then use your new control. For example:
public class MyControl : SomeOtherControl
{
public MyControl()
{
DefaultStyleKey = typeof(MyControl);
}
public static readonly DependencyProperty VisibilityChangedProperty = DependencyProperty.Register(
"VisibilityChanged",
typeof(string),
typeof(MyControl),
new PropertyMetadata("VisibilityChanged event handler"));
public event VisibilityChangedEventHandler VisibilityChanged;
public delegate void VisibilityChangedEventHandler(object sender, EventArgs e);
public new Visibility Visibility
{
get { return base.Visibility; }
set
{
if (base.Visibility == value) return;
base.Visibility = value;
VisibilityChanged(this, new EventArgs());
}
}
}
或者,当然,如果您可以完全控制控件的源代码,不用担心继承。
Or, of course, if you have complete control of the control's source code, don't bother with the inheritance.
这篇关于Windows Phone 8用户控件的VisibleChanged事件在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!