为什么SelectTemplate方法在调试模式下运行2次? [英] Why is the SelectTemplate Method run 2 times in debug mode?

查看:191
本文介绍了为什么SelectTemplate方法在调试模式下运行2次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调试此类SelectTemplate方法运行2次,但为什么?

debuging this class the SelectTemplate Method is run 2 times, but why?

第一次项目始终为空。

public class PersonDataTemplateSelector : DataTemplateSelector
{
    public override DataTemplate SelectTemplate(object item,DependencyObject container)
    {
        if (item is Person)
        {
            Person person = item as Person;

            Window window = Application.Current.MainWindow;

            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode( window))
                return null;

            if (person.Gender == "male")               
                return window.FindResource("boysViewTemplate") as DataTemplate;
            else                
                return window.FindResource("girlsViewTemplate") as DataTemplate;

        }
        return null;
    }
}


推荐答案

您的选择器将提供空或加载,第一次调用是什么让您的选择器有机会提供该模板,而元素正在加载。

If your selector were to provide a look for "Empty" or "Loading", the first call is what gives your selector the opportunity to provide that template while the elements are loading.

这篇关于为什么SelectTemplate方法在调试模式下运行2次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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