问题
In a Silverlight application I have a number of combo boxes with data content. How do I set the width of the combo box so that it can accommodate its widest item?
I have created a hack that works in WPF, but it does not work in Silverlight – which is both unfortunately and expected ;^(
I might be able to create a workaround by measuring the width of the text but that would be a very hard coded implementation so I would like to find another way.
I cannot really believe that this is not a supported scenario, but I have not been able to find an solution. I hope there is something I have missed…
回答1:
It would be hardcoded if you databound, then cycled thru the elements measuring the text width? Seems fairly dynamic (if clunky)
来源:https://stackoverflow.com/questions/1477006/setting-the-width-of-a-silverlight-combo-box-to-accommodate-its-widest-item