Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Add Controls To Grid At Runtime
Message
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01464044
Message ID:
01464205
Views:
27
>>>>I'm in a WPF app, and I want to add controls to a grid at runtime. I have:
>>>>
>>>>
>>>>private void LoadView(ViewModelBase View)
>>>>{
>>>>    Type ViewType = View.GetType();
>>>>
>>>>    switch (ViewType.Name.ToLower())
>>>>    {
>>>>        case "groupviewmodel":
>>>>            CurrentView = new GroupViewModel();
>>>>            CurrentControl = new crlGroupView();
>>>>            break;
>>>>
>>>>        case "ruleviewmodel":
>>>>            CurrentView = new RuleViewModel();
>>>>            CurrentControl = new crlRuleTree();
>>>>            break;
>>>>    }
>>>>
>>>>    CurrentControl.DataContext = CurrentView;
>>>>
>>>>    grdMain.Children.Add(CurrentControl);
>>>>    Grid.SetRow(CurrentControl, 1);
>>>>    Grid.SetColumn(CurrentControl, 0);
>>>>    grdMain.Children.Add(CurrentControl);
>>>>}
>>>>
>>>>
>>>>The control does not appear. Anyone know what's wrong?
>>>
>>>CurrentControl.Visibility = Visibility.Visible;
>>
>>No change.
>
>Well that step was required and was missing. I also noticed you have grdMain.Children.Add(CurrentControl); in your code twice, I'm assuming that isn't in your real code as it should throw an error at run time if it was. (Or are you some how catching that error and ignoring it?)
>
>Beyond that I would create a simple project that demonstrates the problem and give us full code to look at.


I figured it out. The control was in the wrong grid row, so it was behind another control.

Thanks
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform