如何手动触发搜索功能

时间:2013-05-28 04:29:03

标签: visual-studio-lightswitch

在我的屏幕中,我创建了一个选项卡控件,其中包含每个选项卡的多个表/查询。为解决某些性能问题,每个表都禁用了“自动执行查询”选项。我能够手动加载表并进行排序和分页工作。但是,内置搜索功能不再起作用。

以下是屏幕的代码段:

partial void MyScreen_Activated()
{
   this.FindControl("children").ControlAvailable += new EventHandler(TabControlAvailableHandler);
}

void TabControlAvailableHandler(object sender, ControlAvailableEventArgs e)
{
    TabControl control = e.Control as TabControl;
    control.SelectionChanged += TabControlChangeHandler;
}

private void TabControlChangeHandler(object sender, SelectionChangedEventArgs e)
{
    var tab = (TabControl)sender;
    var tabitem = tab.SelectedItem as TabItem;

    if (tabitem == null) 
    {
        return;
    }

    var cip = tabitem.Content as Microsoft.LightSwitch.Presentation.Framework.ContentItemPresenter;

    if (cip == null) 
    {
        return;
    }

    LightSwitchApplication.UserCode.Helpers.LightswitchUiHelper.LoadContentItemValues(cip.ContentItem);
 }

我的朋友创建了一个特殊帮手,并解决了排序/分页问题。

以下是帮助程序的代码片段:

///
/// Recursively loads the bindings of the content item and its ChildItems.
///
/// The dispatcher.
/// The content item.
internal static void LoadContentItemValues(IDispatcher screenDispatcher, IContentItem contentItem)
{
    foreach (IContentItem tmp in contentItem.ChildItems) 
    {
        LoadContentItemValues(tmp);
    }

    if (contentItem.Value != null) 
    {
        LoadMethod(contentItem);

        var objectWithDetails = contentItem.Value as Microsoft.LightSwitch.IObjectWithDetails;
        var detailsWithModel = objectWithDetails == null ? null : objectWithDetails.Details as Microsoft.LightSwitch.Details.IDetailsWithModel;
        var contentProperty = detailsWithModel as INotifyPropertyChanged;

        if (contentProperty != null) 
        {
            Dispatchers.Main.Invoke(() => {
                contentProperty.PropertyChanged += (s, e) => {
                    switch (e.PropertyName) 
                    {
                        case "PageNumber":
                        case "SortDescriptors":
                            screenDispatcher.BeginInvoke(() => {
                                LoadMethod(contentItem);
                            });
                            break;
                    }
                };
            });
        }
    }
}

///
/// Execute the Load() method of the value.
///
/// The content item.
static void LoadMethod(IContentItem contentItem)
{
    if (contentItem.Value != null) 
    {
        var loadmethod = contentItem.Value.GetType().GetMethod("Load");

        if (loadmethod != null) 
        {
            loadmethod.Invoke(contentItem.Value, null);
        }
    }
}

问题是我无法获得使内置搜索功能正常工作的正确解决方案。我在这里错过了什么吗?所有可能的解决方案将非常感谢。提前致谢!

问候,
艾伦托伦蒂诺

0 个答案:

没有答案