Infosys Microsoft Alliance and Solutions blog

« Expression Blend issue with Globalized WPF Application | Main | White paper on Monitoring Workflows with WF »

WPF - TextBox memory leak issue

Earlier today on the WPF Forum I hit upon this issue about memory leak in TextBox. MS has responded saying it is by design. I am not entirely convinced as to how consuming unlimited memory could be a good design decision. I have been using WPF for a while now and wasn't even aware of this property on TextBox. I am sure many others won't be.

Anyway, the solution discussed there is to set the UndoLimit property of TextBox to 0. Instead of setting this for all TextBoxes in your code, it can more easily set in App.xaml as an application resource so that it is applicable to all TextBoxes by default. You can explicitly undo for specific ones via code or local property setting.

    <Application.Resources>  
        <Style TargetType="{x:Type TextBox}"> 
            <Setter Property="UndoLimit" Value="0" /> 
        </Style> 
    </Application.Resources>

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Please key in the two words you see in the box to validate your identity as an authentic user and reduce spam.

Subscribe to this blog's feed

Follow us on

Blogger Profiles

Infosys on Twitter