xaml - Using the selected tab in a TabControl to clear a variable - WPF -


i have window contains a tabcontrol 2 tabitems inside it. inside second tab, there textbox binding string property inside view model. want able clear property (or textbox since bound will association, clear property) whenever user clicks on different tab (and if user closes window). i'm hoping can achieve xaml since trying follow mvvm pattern (so no code behind , view model shouldn't know of tabcontrol or textbox in view).

i have tried few different things , can't quite working , while i'm getting better @ wpf, i'm still new it. inside tabs have listviews , comboboxes, understanding bubble selectionchanged event (same when tab selection changed) should stay away that. appreciated.

here 1 of attempts (snippet showing gist):

<tabcontrol> <tabitem>     ...stuff in first tab goes here </tabitem>  <tabitem header="rules">     <tabitem.style>         <style>             <style.triggers>                 <datatrigger binding="{isselected}" value="true">                     <setter targetname="userbox" property="text" value="" />                 </datatrigger>             </style.triggers>         </style>     </tabitem.style>       <groupbox>         <uniformgrid>             <listview itemssource="{binding source={staticresource rulesviewmodel}, path=ruleslist}">                 <listview.view>                     <gridview>                         <gridviewcolumn header="rules"/>                     </gridview>                 </listview.view>             </listview>              <dockpanel>                 <textbox name="userbox" text="{binding source={staticresource rulesviewmodel}, path=user}" />             </dockpanel>         </uniformgrid>     </groupbox> </tabitem> 

i'm pretty sure line reads binding="{isselected}" wrong. i'm not sure how target correct property. ideas?

you need set selectedindex = -1 of tab content want clear on other tabs click.

selectedindex = -1 of default tab making tab default one. condition becomes that

if selectedindex ! = -1, text should cleared or @ application shutdown, text should cleared

i've provided logic, code can written :)


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -