Monday 15 July 2013

c# - How to contain tab control from buttons -



c# - How to contain tab control from buttons -

i have next code chunk (apologies block)

<canvas horizontalalignment="left" height="439" verticalalignment="top" width="1171" canvas.left="10" canvas.top="10" margin="0,0,0,-1" > <tabcontrol height="419" canvas.left="10" canvas.top="10" width="1151"> <tabitem x:name="maintab" header="main"> <grid> <canvas horizontalalignment="left" height="100" verticalalignment="top" width="741" canvas.left="55" canvas.top="118" margin="10,91,0,0"> <controls:tile title="add shift" tiltfactor="2" width="100" height="100" count="1" margin="0" click="tiletabcontrol"> </controls:tile> <controls:tile title="recorded shifts" tiltfactor="2" width="136" height="100" count="2" margin="0" canvas.left="105"> </controls:tile> <controls:tile title="details of pay" tiltfactor="2" width="136" height="100" count="3" margin="0" canvas.left="246"> </controls:tile> <controls:tile title="account settings" tiltfactor="2" width="158" height="100" count="4" margin="0" canvas.left="387"> </controls:tile> <controls:tile title="view shifts month" tiltfactor="2" width="191" height="100" count="5" margin="0" canvas.left="550"> </controls:tile> </canvas> </grid> </tabitem> <tabitem x:name="recordedshifts" header="recorded shifts"> <grid background="#ffe5e5e5"/> </tabitem> <tabitem x:name="paydetails" header="pay details"> <grid background="#ffe5e5e5"/> </tabitem> <tabitem x:name="accountsettings" header="account settings"> <grid background="#ffe5e5e5"/> </tabitem> <tabitem x:name="shiftsbymonth" header="shifts month"> <grid background="#ffe5e5e5"/> </tabitem> <tabitem x:name="newshift" header="new shift "> <grid background="#ffe5e5e5"/> </tabitem> </tabcontrol> </canvas>

i'm trying figure out method send info same handler command changing of tabs. i've got

private void tiletabcontrol(object sender, routedeventargs e,string u) { messagebox.show(u.tostring()); <!-- test if u correctly set--> }

from method, plan alter selected tab doing along lines of:

private void tiletabcontrol(object sender, routedeventargs e,string u) { //messagebox.show(u.tostring()); u.isselected = true; }

which switch right tab. sense if method possible, it'll minimize duplicated functions voids serve 1 purpose switch different tabs.

i have tried:

count="1" margin="0" click="tiletabcontrol(maintab)">

which returned:

error 1 click="tiletabcontrol(test)" not valid. 'addnewshifttileclick(test)' not valid event handler method name. instance methods on generated or code-behind class valid.

i have researched google on how along these lines, i've discovered basic questions inquire changing tab command control it's self, churns out code snippets along lines of:

tabcontrol.tabs[tabnumber].isselected=true;

which when attempting modify , include current code set turned out no avail.

there basic approach create new event handler each tile click switch tabs, sense give messy back-end c# coding.

is there different approach or scheme impliment minimize duplicated event handlers perform single purpose?

it seems have managed find work around, before farther additions tab control, have made next changes:

<controls:tile title="add shift" tiltfactor="2" width="100" height="100" count="1" margin="0" tag="newshift" click="tiletabcontrol"> </controls:tile>

with add-on of tag element, give parameter/value within sender object & validate such:

var type = (button)sender; messagebox.show(type.tag.tostring());

which casts sender object button, inturn allow me value parsed within tag element, turn string & print out in textbox. after info manipulations, looks so:

private void tiletabcontrol(object sender, routedeventargs e) { var tab = (button)sender; //messagebox.show(type.tag.tostring()); switch (tab.tag.tostring()) { case "newshift": break; case "recordedshifts": break; case "detailsofpay": break; case "accountsettings": break; case "shiftsbymonth": break; } }

c# wpf tabcontrol

No comments:

Post a Comment