I think problem is with
<Style BasedOn="{StaticResource MainButton}" TargetType="Button/>
should have
<Style BasedOn="{DynamicResource MainButton}" TargetType="Button"/>
because it might be the case that MainButton style is not available at runtime
You can also try cleaning the solution and Rebuilding it. it might also causes the problem.