c# - Changing text in textblock to italicized on MouseEnter -
i have textblock contains non-italicized text. when mouse enters textblock, text changes through use of code behind. code behind have ability change text italicized. have far:
xaml:
<textblock x:name="block1" background="cyan" foreground="{staticresource mybrush2}" grid.column="0" grid.row="0" height="30" horizontalalignment="center" mouseenter="textblock_mouseenter" mouseleave="textblock_mouseleave" padding="0,7,0,0" text ="hover me!" textalignment="center" width="100"/>
code behind (c#):
public void textblock_mouseenter(object sender, mouseeventargs e) { string blockname = ((textblock)sender).name; var block = sender textblock; if (block != null && blockname == "block1") { block.text = "yo! i'm textblock1"; } }
i have looked using system.drawing , use of fontstyle.italic; although unsuccessful of making work.
this xaml
made for
<textblock x:name="block1" background="cyan" foreground="{staticresource mybrush2}" grid.column="0" grid.row="0" height="30" horizontalalignment="center" mouseenter="textblock_mouseenter" mouseleave="textblock_mouseleave" padding="0,7,0,0" text ="hover me!" textalignment="center" width="100"> <textblock.style> <style targettype="textblock"> <style.triggers> <trigger property="ismouseover" value="true"> <setter property="fontstyle" value="italic" /> </trigger> </style.triggers> </style> </textblock.style> </textblock>
but, if want to, here's example of how might implement functionality code-behind.
private void block1_mouseenter(object sender, mouseeventargs e) { setfontstyle(fontstyles.italic); } private void block1_mouseleave(object sender, mouseeventargs e) { setfontstyle(fontstyles.normal); } private void setfontstyle(fontstyle style) { block1.fontstyle = style; }
Comments
Post a Comment