How do WPF toolbars change their buttons' styles? -
in wpf, if put button inside toolbar, button automagically gets different style: no border default, different hover effects, etc. mechanism wpf use accomplish that?
i know how restyle buttons in program, putting style targettype="button"
resources in app.xaml. know how restyle buttons in single parent panel, putting same style targettype="button"
panel's resources. don't know how make reusable, can apply multiple different panels (but not whole app) , have restyle buttons in panels.
toolbar has magic make "apply children" style reusable. how that?
it applies style in preparecontainerforitemoverride, looks like:
protected override void preparecontainerforitemoverride(dependencyobject element, object item) { base.preparecontainerforitemoverride(element, item); frameworkelement element2 = element frameworkelement; if (element2 != null) { // ... resourcekey name = null; if (type == typeof(button)) { name = buttonstylekey; } else if (type == typeof(togglebutton)) { name = togglebuttonstylekey; } else if (type == typeof(separator)) { name = separatorstylekey; } // ... element2.defaultstylekey = name; } }
Comments
Post a Comment