Preheat oven to 350ºF and coat a 3 quart baking dish in nonstick cooking spray. Melt butter in a large skillet over medium heat. Add onion and cook, stirring occasionally, for 4 minutes. Add garlic and cook for another 1-2 minutes until garlic is fragrant and onions are tender. Sprinkle in flour and cook, stirring, for 1 minute. Whisk in milk and cook until sauce is thickened and bubbly, about 4-5 minutes. Add salt, pepper, and cheese and stir until cheese is melted. Remove sauce from heat.Place half the sliced potatoes in bottom of prepared baking dish. Top with half the ham, then pour on half the sauce. Repeat layers and cover dish tightly with foil. Bake covered for 45 minutes, then remove foil and bake for another 20-30 minutes until potatoes are tender and top is golden and bubbly. Let cool 10-15 minutes before serving. Garnish with fresh chopped parsley, if desired.