开发者

I get "Value does not fall within the expected range." when I try to add Custom control to Stack Panel

I get "Value does not fall within the expected range." when I try to add Custom control to Stack Panel.

I tried to assign a unique name for the control's name but of no avail.

Here's the code:

CurrentProjectControl currentProjectControl;

            foreach (var resource in ProjectResources)
            {
                //Random rand = new Random();
                currentProjectControl = new CurrentProjectControl(resource.ProjectCode, _projects, _timesheets, _projectResources);
                currentProjectControl.Name = (new Guid()).ToString();
                _scorecardView.CurrentProjectStackPanel.Children.Add(currentProjectControl);
            }

Could any one开发者_如何学JAVA shed some light on this issue?


Actually I have found the problem. It has nothing to do with the Custom controls, its the statement:

currentProjectControl.Name = (new Guid()).ToString();

which returns the same results which leads to the error.

So correct code snippet is:

CurrentProjectControl currentProjectControl;

foreach (var resource in ProjectResources)
{
    currentProjectControl = new CurrentProjectControl(resource.ProjectCode, _projects, _timesheets, _projectResources);
    currentProjectControl.Name = Guid.NewGuid().ToString();
    _scorecardView.CurrentProjectStackPanel.Children.Add(currentProjectControl);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜