德行：moral integrity or disgusting? The question is quite simple, how it is possible that 德行 means two completely opposite things?

And when facing this character, how can I know what it means?
The ROC (Taiwan) 教育部國語辭 is a very useful resource, and often has good examples. Here's what it says for 德行:

1) 仁慈的行為 humane behavior: Honglou Meng: 倘或日後咱們遇見了，那時我又怎麼報你的德行。 If we meet another day, How can I repay your kind deed?

2) 諷刺或鄙視讓人產生惡感的儀態或行止 used to mock or sneer at despicable behavior or deportment: 他那副爛醉的德行，令人討厭 His drunken hijinks were disgusting.

德性 is a little more complicated, but still similar. Skipping the first meaning, it has:

1 道德品性 moral character: from Rulin Waishi 這位小姐，德性溫良，才貌出眾 The young lady has a kind and gentle nature, and is both beautiful and talented.

2 (same as 德行 2):  瞧他那副猥猥瑣瑣的德性，就知道做不了什麼大事 One look at that nerdish face and you know he'll never amount to anything.

So both words have a 'straight' use and a 'sarcastic' use.  Context determines which is which.

Postscript:

A couple of other answers below note that there is another pronunciation. I've never heard this in Taiwan, but I have now found a reference in the Pinyin Chinese-English Dictionary, which says:

déxing (xing=輕聲): &lt;方> disgusting; shameful; 那個家伙真德行. That fellow is really disgusting.

So the PY Dictionary regards this as a dialectal usage.