Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Add Controls To Grid At Runtime
Message
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Divers
Thread ID:
01464044
Message ID:
01464209
Vues:
20
>>>>>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

Cool glad you got it!
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform