Canvas max width

Is there an easy way to set a max Canvas width, which means fitHeight is enabled and during resize until that maxWidth the fitWidth should be false, but after the maxWidth the fitWidth should be true.
Or should I do it manually?