TextBox with CurrencyFormat and PropertyChanged trigger doesn't accept text right

后端 未结 1 793
滥情空心
滥情空心 2021-01-23 23:24

I have a TextBox in a WPF window bound to a dependency property of the window of type double (see below). Whenever the user types in the TextBox

相关标签:
1条回答
  • 2021-01-23 23:40

    This is caused by it trying to apply the formatting after every character press.

    As an alternative, I usually just style the TextBox so it only applies formatting when it's not being edited

    <Style TargetType="{x:Type TextBox}">
        <Setter Property="Text" Value="{Binding SomeValue, StringFormat=C}" />
        <Style.Triggers>
            <Trigger Property="IsKeyboardFocusWithin" Value="True">
                <Setter Property="Text" Value="{Binding SomeValue, UpdateSourceTrigger=PropertyChanged}" />
            </Trigger>
        </Style.Triggers>
    </Style>
    
    0 讨论(0)
提交回复
热议问题