[英]How to check if an UIElement is a Panorama or not
I have a code like this 我有这样的代码
foreach(UIElement iue in layout.Children)
{
if (iue is Panorama)
{
//some code
}
}
but this is always false. 但这总是错误的。
I also tried 我也试过
foreach(UIElement iue in layout.Children)
{
if (iue.getType() == typeof(Panorama))
{
//some code
}
}
with no success. 没有成功。
I wrote a test app and your code should work. 我编写了一个测试应用,您的代码应该可以正常工作。 If you have double checked everything else keep in mind that the
Children
property will return top level elements only. 如果您仔细检查了其他所有内容,请记住,
Children
属性将仅返回顶级元素。 If your Panorama
control is a child element then you will need to get to it using the Children
property of the parent control. 如果您的
Panorama
控件是子元素,则需要使用父控件的Children
属性来访问它。 Another thing to check is that the namespace of the control you used in the line typeof(Panorama)
is Microsoft.Phone.Controls
. 要检查的另一件事是,您在
typeof(Panorama)
行中使用的控件的命名空间是Microsoft.Phone.Controls
。 You can do this by hitting F12 when you cursor is on the word Panorama
. 您可以通过在光标位于
Panorama
单词上单击F12来完成此操作。
Just a little change in your code. 只需对您的代码进行一点更改。 try this, may will help you.
试试这个,可能会帮助您。
foreach(UIElement iue in layout.Children)
{
if (this.IsPanorama(iue ))
{
//some code
//Panorama control
}
else
{
//not aPanorama control
}
}
//just check whether a UI element is panorama or not //只检查UI元素是否为全景图
private bool IsPanorama(UIElement element)
{
bool isPanorama =false;
try{
Panorama p = (Panorama)element;
isPanorama = true;
return isPanorama ;
}
catch(Exception ex)
{
isPanorama = false;
return isPanorama ;
}
}
Just checked the XAML again and found that there was no Panorama but a UserControl that was inherited from Panorama with name PanoramaFullScreen (to have full screen PanoramaItem). 只需再次检查XAML,发现没有Panorama,而是一个从Panorama继承的名称为PanoramaFullScreen(具有全屏PanoramaItem)的UserControl。
Thank you everyone for the response though. 谢谢大家的回应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.