wpf - Changing TabStripPlacement on ButtonClick -
i new wpf , change tapstripplacement on buttonclick. tried finding solution myself couldnt it. happy on fast solution.
this code:
<window x:class="pages.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="tabcontrol" height="350" width="525"> <window.resources> <solidcolorbrush x:key="foreground" color="#ff9531b1"></solidcolorbrush> <solidcolorbrush x:key="background" color="transparent"></solidcolorbrush> <controltemplate x:key="tabitemcontroltemplate" targettype="{x:type tabitem}"> <grid snapstodevicepixels="true"> <border x:name="bd" borderbrush="{staticresource foreground}" borderthickness="0" padding="{templatebinding padding}"> <border.style> <style targettype="{x:type border}"> <setter property="background" value="{staticresource background}"/> <style.triggers> <datatrigger binding="{binding relativesource={relativesource templatedparent}, path=isselected}" value="true"> <setter property="background" value="{binding relativesource={relativesource templatedparent}, path=background}" /> </datatrigger> <datatrigger binding="{binding relativesource={relativesource templatedparent}, path=ismouseover}" value="true"> <setter property="background" value="{binding relativesource={relativesource templatedparent}, path=background}" /> </datatrigger> </style.triggers> </style> </border.style> <contentpresenter x:name="content" contenttemplate="{templatebinding headertemplate}" content="{templatebinding header}" contentstringformat="{templatebinding headerstringformat}" contentsource="header" horizontalalignment="{binding horizontalcontentalignment, relativesource={relativesource findancestor, ancestorlevel=1, ancestortype={x:type itemscontrol}}}" recognizesaccesskey="true" snapstodevicepixels="{templatebinding snapstodevicepixels}" verticalalignment="{binding verticalcontentalignment, relativesource={relativesource findancestor, ancestorlevel=1, ancestortype={x:type itemscontrol}}}"/> </border> </grid> <controltemplate.triggers> <trigger property="ismouseover" value="true"> <setter targetname="bd" property="background" value="{staticresource foreground}"></setter> <setter targetname="content" property="textblock.foreground" value="white"></setter> <setter targetname="content" property="textblock.fontweight" value="heavy"></setter> </trigger> <multitrigger > <multitrigger.conditions > <condition property="isselected" value="true"></condition> <condition property="ismouseover" value="false"></condition> </multitrigger.conditions> <setter targetname="content" property="textblock.foreground" value="{staticresource foreground}"></setter> <setter targetname="content" property="textblock.fontweight" value="heavy"></setter> </multitrigger> </controltemplate.triggers> </controltemplate> </window.resources> <grid> <grid.columndefinitions> <columndefinition></columndefinition> <columndefinition></columndefinition> </grid.columndefinitions> <stackpanel grid.column="1"> <button x:name="btntop">top</button> <button name="btnright">right</button> <button name="btnbottom">bottom</button> <button name="btnleft">left</button> </stackpanel> <tabcontrol grid.column="0" x:name="mycontrol" height="200" background="transparent" borderthickness="0,1,0,0" borderbrush="{staticresource foreground}" tabstripplacement="top"> <tabitem header="tab1" background="transparent" template="{dynamicresource tabitemcontroltemplate}"/> <tabitem header="tab2" background="transparent" template="{dynamicresource tabitemcontroltemplate}"/> <tabitem header="tab3" background="transparent" template="{dynamicresource tabitemcontroltemplate}"/> </tabcontrol> </grid>
thanks in advance
try out
<dockpanel> <stackpanel grid.column="1" dockpanel.dock="top" orientation="horizontal"> <button x:name="btntop" click="btntop_click">top</button> <button name="btnright" click="btnright_click">right</button> <button name="btnbottom" click="btnbottom_click">bottom</button> <button name="btnleft" click="btnleft_click">left</button> </stackpanel> <tabcontrol name="tabcontrol" dockpanel.dock="bottom"> <tabitem header="tab1"></tabitem> <tabitem header="tab2"></tabitem> </tabcontrol> </dockpanel>
in code behind file
private void btntop_click(object sender, routedeventargs e) { tabcontrol.tabstripplacement = dock.top; } private void btnright_click(object sender, routedeventargs e) { tabcontrol.tabstripplacement = dock.right; } private void btnbottom_click(object sender, routedeventargs e) { tabcontrol.tabstripplacement = dock.bottom; } private void btnleft_click(object sender, routedeventargs e) { tabcontrol.tabstripplacement = dock.left; }
Comments
Post a Comment