c# - Refactor XAML in WPF -
my xaml has got long , hard maintain. wondering if there way refactoring?
here simple example:
<window x:class="refactorxaml.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <grid> <stackpanel> <button>new</button> <button>open</button> </stackpanel> </grid> </window>
how can refactor stackpanel
section , write this?
<window x:class="refactorxaml.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <grid> // refactored markup </grid> </window>
you put buttons in user control, make this:
<window … xmlns:my="clr-namespace:somenamespace"> <grid> <my:newandopenbuttons /> </grid> </window>
you replace grid items control includes buttons, way impose many restrictions on other content, wouldn’t that.
so above, user control this:
<usercontrol x:class="somenamespace.newandopenbuttons" …> <stackpanel> <button>new</button> <button>open</button> </stackpanel> </usercontrol>
Comments
Post a Comment