You can apply to change your legal name and sex designation at the same time, but they are separate applications.
Many people complete their legal name change first. Once they receive their Change of Name Certificate, they can use it to update their provincial and federal records while also updating their sex designation.