添加控件會導致 Silverlight 掛起 (Adding controls causes silverlight to hang)


問題描述

添加控件會導致 Silverlight 掛起 (Adding controls causes silverlight to hang)

I have a very strange issue that I'm finding it extremely hard to debug, thus I once more turn to the SO community. :‑)

First a bit on my setup (note! I'm new to silverlight, just learning by doing, so my entire premise might be wrong!):

I have some root nodes (forms) under which are some leaves (questions). Now, I simply want to show / hide the questions depending on which form is currently selected ‑ fairly easy.

I do the following:

  • A number of controls are added to a LayoutControl (I'm using the DeveloperExpress components)
  • When you select another form, the created controls are saved in a list on the previously selected form
  • When you select a form, the list of controls is iterated through, and each element is added to my layoutcontrol again

When I save the elements in the list on a Form I make sure to first .Remove() them from their parent to make sure there are no issues with that.

And, this works.

If I have 1 or controls.

If I have MORE than that, everything is added as usual, no exception is thrown ‑ but Silverlight apparently does an infinite loop somehow? No matter if I run it in IE or Chrome, it just crashes the browser! (Or, I guess, the browser plugin).

I've tried pausing the debugger during this to see where the problem is, but it just stops in "external code". I don't think a code sample will do much good, but here's the two methods that save and load the elements: (Note: AddControl is a method I've defined ‑ it wraps the element in another control to provide a bit of functionality. Likewise .MyChildren removes the control from the wrapper using .Remove() and returns it)

    private void LoadElementsFromCurrentForm()
    {
        foreach (var child in _currentForm.Elements)
        {
            layoutControl1.AddControl(child);
        }
    }

    private void SetElementsOnCurrentForm()
    {
        _currentForm.Elements.Clear();
        foreach (var child in layoutControl1.MyChildren)
        {
            _currentForm.Elements.Add(child);
        }
    }

How do I even go about debugging this!? I don't know if it matters, but all these controls have a unique name as well.

Regards

Søren

‑‑‑‑‑

參考解法

方法 1:

To take full advantage of Silverlight you should try to use XAML to do the markup of design.  If you want to make a list of questions use e Listbox or ItemsControl.  Then you can style each item in the list to "look right". If you bind the listbox to ObservableCollection you just add or remove in the list and the gui will be updated according to whats in your list. 

Take a look at MVVM which works really good with Silverlight.

(by FafnrRichard L)

參考文件

  1. Adding controls causes silverlight to hang (CC BY‑SA 3.0/4.0)

#devexpress #user-controls #silverlight-4.0 #silverlight






相關問題

修改 aspxgrid 中的列以顯示超鏈接和支持組 (Modify column in aspxgrid to display a hyper link and support group by)

沒有標誌的Javascript不區分大小寫的正則表達式 (Javascript case insensitive regex without flags)

MVC 4 - Gặp lỗi khi cố gắng thêm một báo cáo mới (MVC 4 - Getting error while trying to add a new report)

網格列包含 int64 值,但過濾器顯示字符串並且不起作用/ (Grid column contains int64 values but filter shows strings and doesn't work/)

我應該每年為保持 devexpress 應用程序的運行付費嗎 (Should I pay every year for keep devexpress app running)

Excel 和 Word DevExpress (Excel & Word DevExpress)

用於 ASP.NET Web 應用程序的 DevExpress 與 Telerik 網格 (DevExpress vs. Telerik grids for ASP.NET web applications)

添加控件會導致 Silverlight 掛起 (Adding controls causes silverlight to hang)

根據用戶控件的大小調整面板的大小 (Resizing a Panels based on the size of user control)

vs2010 asp.net設置斷點問題 (Problem in setting breakpoint in vs2010 asp.net)

單擊按鈕後行命令不觸發 (Rowcommand do not fire after clicking button)

DevExpress 11.1 在 IIS 7+ 中不起作用 (DevExpress 11.1 not functional in IIS 7+)







留言討論