What factors have made on-train catering no longer viable in most cases?
By its nature, on-board catering generally offers limited choice, questionable quality and poor value for money. Obviously Intercity type stock with a proper shop/buffet car can offer more, but a trolley service is limited by the space available on the trolley. They've got no ability to keep things warm or cold for any length of time, so everything apart from hot drinks ends up at ambient temperature. I don't fancy buying a warm can of lager for far more than I could pay for a cold pint in Wetherspoons. If I was relying on at-seat catering, I'd likely want some sort of "proper" food, not just a chocolate bar, bag of crisps or some sweets.
Which leads into my next point. These days there's an absolute abundance of food and drink options in even the smallest of towns. This includes options for buying food and drink to take onto the train or simply options to eat/drink both immediately before and after the journey. Even Poundland offers a £3 meal deal. There are branches of Gregg's/Subway/Starbucks/Costa absolutely everywhere. Many convenience stores offer a range of sandwiches and snacks and some sort of coffee machine.
I don't drink the stuff, but I can understand how somebody doing, say, Liverpool to Norwich might want another cup (or two) of coffee en-route, even if they'd brought one on-board with them. Outside of that, I'd say trolley sales are more of either a distress purchase for those who were less prepared, or an impulse purchase for those who wouldn't otherwise have purchased anything, but see a trolley of cans and packets going past and feel the desire to grab something.
As for improvements? Maybe not possible with existing rolling stock, but on new stock perhaps something similar to the catering cupboard on the 197s. Can take up less space than a traditional buffet/shop counter but could still provide a combination of ambient storage, fridge and either a microwave or hot cabinet. With a roaming host and/or at seat web ordering. You could still restock en-route, so it wouldn't need to be huge, but it would enable you to sell genuinely cold drinks, things like sandwiches or pasta pots and hot options - even just something basic like burgers/hot dogs, pizza/toastie slices and maybe sausage rolls or similar; the sort of stuff you might find in a Co-op/Spar hot cabinet.