In you're first example, what you have is dynamic styling.  IOW, in response to an event you modify some attributes (usually related to the visual presentation) on the control.  In this case, the all XAML approach is the most appropriate, and "reusing code" is straightforward.  You design a template and apply it to all controls of a given type or to individual controls.  This is superior for numerous reasons to the HTML/JavaScript example.  Of course, as pointed out, you also have the option of doing it in a code behind event handler, the same as you'd do with HTML/JavaScript.

Your second example isn't a styling thing.  You're doing more than setting some attributes.  In this case, you're going to have to go down the code behind route, and as I just said, this means code reuse is identical to your HTML/JavaScript example.