step 1
Find out the slope of segment XB
m=(-2-4)/(8-2)
m=-6/6
m=-1
Remember that, if two lines are perpendicular, then their slopes are negative reciprocal
that means
the slope of the perpendicular bisector is
m=1
step 2
Find out the midpoint segment XB

step 3
Find out the equation of the perpendicular bisector
y=mx+b
we have
m=1
point M(5,1)
substitute and solve for b
1=(1)(5)+b
1=5+b
b=1-5
b=-4
therefore
the equation is
y=x-4