Preheat your oven to 375°F (190°C). Grease a 9×13 inch baking dish with butter or cooking spray.
In a saucepan over medium heat, melt the butter. Stir in the flour and cook for about 1 minute until it forms a paste-like consistency.
Gradually whisk in the milk, stirring constantly until the mixture is smooth and thickened.
Stir in the salt, pepper, garlic powder, and paprika (if using). Remove from heat.
Layer half of the sliced potatoes in the bottom of the prepared baking dish. Top with half of the diced ham and half of the sliced onion. Sprinkle with half of the shredded cheddar cheese. Repeat the layers with the remaining potatoes, ham, onion, and cheese.
Pour the prepared sauce evenly over the layers in the baking dish.
Cover the baking dish with aluminum foil and bake in the preheated oven for 45 minutes.
Remove the foil and continue baking for an additional 15-20 minutes or until the potatoes are tender and the top is golden brown and bubbly.