未检测到已安装的组件元素已经是另一个元素的子元素加载 SearchBox 时出现 UWP 错误

问题描述

我在加载 SearchBox 时遇到此间歇性错误,但不确定我在这里做错了什么。项目已从 Windows 8.1 应用平台迁移到 UWP。

未检测到已安装的组件。元素已经是 另一个元素。

我在 App.g.i.cs 中收到此错误。任何 CS 文件中都没有抛出异常。

enter image description here

这是代码页面中有两个 SearchBox 元素,我想知道这是否可能是问题所在。

                <TextBlock 
                    Visibility="{
                        Binding ServiceReview.ServiceReviewType_Id,Converter={StaticResource ConsumerTypetoVisibleConverter},Mode=OneWay
                    }"
                    Style="{StaticResource FormTextBlock}"
                    Text="Individual's Name"/>
                <SearchBox 
                    Visibility="{
                        Binding ServiceReview.ServiceReviewType_Id,Mode=OneWay
                    }"
                    x:Name="IndividualSearchBox"
                    Style="{StaticResource FormSearchBox}"
                    PlaceholderText="Search by Individual's Name"
                    SuggestionsRequested="IndividualSearchBox_OnSuggestionsRequested"
                    ResultSuggestionChosen="IndividualSearchBox_OnResultSuggestionChosen"
                    SearchHistoryEnabled="False">
                </SearchBox>
 
                    <TextBlock
                                Style="{StaticResource FormTextBlock}"
                                Text="Search Team Members To Add"/>
                    <SearchBox
                                x:Name="UserSearchBox"
                                Style="{StaticResource FormSearchBox}"
                                PlaceholderText="Search by Team Member's Name"
                                SuggestionsRequested="UserSearchBox_OnSuggestionsRequested"
                                ResultSuggestionChosen="UserSearchBox_OnResultSuggestionChosen"
                        SearchHistoryEnabled="False">
                    </SearchBox>

用户搜索框给出了错误

我们像这样加载数据:

 private async void UserSearchBox_OnSuggestionsRequested(SearchBox sender,SearchBoxSuggestionsRequestedEventArgs args)
    {
        try
        {

       
        if (string.IsNullOrEmpty(args.QueryText))
        {
            return;
        }

        var collection = args.Request.SearchSuggestionCollection;

        if (_oldUserQuery == args.QueryText) return;

        var deferral = args.Request.GetDeferral();

        List<Employee> employees = await _employeeService.SearchEmployees(args.QueryText);

        foreach (var employee in employees)
        {
            collection.AppendResultSuggestion(employee.FullName,string.Empty,employee.EmployeeId.ToString(),RandomAccessstreamReference.CreateFromUri(
                new Uri("http://www.dotnettoscana.org/logo.png")),string.Empty);
        }

        deferral.Complete();

        _oldUserQuery = args.QueryText;
        }
        catch (Exception ex)            {

            throw;
        }
    }

这里是与控件相关的样式。

<Style targettype="SearchBox" x:Key="FormSearchBox">
        <Setter Property="Height" Value="55"/>
        <!--<Setter Property="SearchHistoryEnabled" Value="False"/>-->
        <Setter Property="Margin" Value="20,15"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="Width" Value="380" />
        <!--Testing by moving below contents from SearchBox-->
        <Setter Property="VerticalAlignment" Value="Top"/>
        <Setter Property="Padding" Value="{StaticResource MediumThickness}"/>
        <Setter Property="BorderBrush" Value="{StaticResource BorderBrushColor}"/>
        <Setter Property="BorderThickness" Value="{StaticResource BorderThickness}"/>
        <Setter Property="FontSize" Value="{StaticResource AppFontSize}"/>
    </Style>

任何有关发现问题的指示将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...