c# - How can I reference a control on a tab from another tab? -
i have wpf mainwindow tab control. 1st tab called persons , has gridview bound persons observable collection. selecting checkboxes , click next button go next tab has identical grid of persons bound selectedpersons. on first tab's next button, apparently need refresh gridview on secondtab.
like datagrid.items.refresh.
i don't know how reference it. this?
public override void nexttab() { ((datagrid)this.maintabs[1].controls["selectedpersonsgridview"]).items.refresh }
i total newbie @ wpf , can see have no idea doing trying do. don't know patterns yet.
if have named control selectedpersonsgridview don't need find control can use it's name reference it.
xaml
<window x:class="wpfapplication1.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <grid> <tabcontrol> <tabitem header="tab1"> <grid background="#ffe5e5e5"> <button content="button" horizontalalignment="left" verticalalignment="top" width="75" margin="22,36,0,0" click="button_click"/> </grid> </tabitem> <tabitem header="tab2"> <grid name="selectedpersonsgridview"> </grid> </tabitem> </tabcontrol> </grid> </window>
and code behind
using system.windows; using system.windows.media; namespace wpfapplication1 { public partial class mainwindow : window { public mainwindow() { initializecomponent(); } private void button_click(object sender, routedeventargs e) { selectedpersonsgridview.background = brushes.red; } } }
Comments
Post a Comment