开发者

Silverlight datagrid not rebinding to new data

开发者 https://www.devze.com 2023-01-26 02:26 出处:网络
I have a datagrid that displays a list of 开发者_StackOverflow社区orders.Above the datagrid, there is a box that filters the orders by capturing the text input and then calling a server side method to

I have a datagrid that displays a list of 开发者_StackOverflow社区orders. Above the datagrid, there is a box that filters the orders by capturing the text input and then calling a server side method to get orders matching the supplied text. This works fine on the page.

I've tried adding a page that passes in parameters via querystring that would automatically apply a filter when the user lands on the page. The code to call the server side method is called correctly and the data is returned correctly, but the datagrid doesn't show the results. If I type the same text into the textbox on the page and search, the results are finally shown on the datagrid. It is almost like the datagrid doesn't see the change the first time the user comes to the page with an automatic filter. Here are some relavent bits:

protected override void OnNavigatedTo(NavigationEventArgs e) {
        if (NavigationContext.QueryString.ContainsKey("filterkeyword") && NavigationContext.QueryString.ContainsKey("filtervalue")) {
            string filterkeyword = NavigationContext.QueryString["filterkeyword"];
            string filtervalue = NavigationContext.QueryString["filtervalue"];

            switch (filterkeyword) {
                default: ApplyDefaultFilter(filtervalue); break;
            }
        } else {
            ApplyDefaultFilter("");
        }
    }

The datagrid is just bound to a data source object and the datasource is not set to auto load. Here are the bits for when a user does submit a search via the filter box:

private void txtFilter_KeyDown(object sender, KeyEventArgs e) {
        if (e.Key == Key.Enter) {
            ApplyDefaultFilter(txtFilter.Text);
            txtFilter.Select(0, txtFilter.Text.Length);
        }
    }

They both call the same methods and return the results, it is just that the textbox somehow tells the page to refresh the datagrid and magically the data appears. Is there an event I can force on the page to cause a refresh of the datagrid?


Does you datasouce object implement INotifyPropertyChanged or if it's a collection, is it an ObservableCollection?

The TextBox rebinds on changes AFAIK.


I added this and it seems to work...though this does seem like a bit of kludge.

void ordersDataSource_LoadedData(object sender, LoadedDataEventArgs e) {
        ordersDataGrid.ItemsSource = e.Entities;
    }

I didn't need it when filtering within the page, but redirecting the user to the page requires this....odd.

0

精彩评论

暂无评论...
验证码 换一张
取 消