One can use a pure function to specify the ticks of a BarLegend.
f[x_, y_] := Sin[1 + x] + 2 Sin[y] + x DensityPlot[f[x, y], {x, 0, 2 π}, {y, 0, 2 π}, PlotLegends -> BarLegend[Automatic, Ticks -> (FindDivisions[{#1, #2, π}, Ceiling[(#2 - #1)/π]] &)]] 