mvvm - How to insert button into Grid from ViewModel C# class in windows 8.1 store app -
i can insert button grid control code behind file
var felem = new button(); felem.content = "button text"; bggrid.children.add(felem); // bggrid defined in xaml
how can add same button grid view model class?
in code-behind of xaml page (xaml.cs) need publicly expose grid
public grid mygrid => bggrid;
then can access viewmodel so:
frame rootframe = window.current.content frame; var page = rootframe.content yourpageclassname; var felem = new button(); felem.content = "button text"; page.mygrid.children.add(felem);
however, not mvvm @ all.
Comments
Post a Comment