WPF
WPF TextBox에 float 바인딩 해서 소수점이 입력되지 않는 문제
leo21c
2021. 7. 9. 19:49
WPF를 이용해서 TextBox에 Float이나 Double 값을 입력 하려고 했는데 소스점이 입력되지 않는 문제가 확인되었다.
이것 저것 검색한 결과 아래와 같은 정보를 찾아서 수정을 진행했다.
Bind textbox to float value. Unable to input dot / comma
When I try to input a DOT or a COMMA in a textbox, for example 1.02 or 83,33 the textbox prevents me to input such a value (and the input turns red). The textbox is bound to a float property. Why? I
stackoverflow.com
<TextBox Name="txtPower" Height="23" TextWrapping="Wrap" Text="{Binding Path=Power, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,StringFormat=N2}"></TextBox>
- I used StringFormat={}{##.##} and this works for me. Not sure whats N2. Thanks! – LukeSolar Jan 30 '13 at 10:56
위와 같은 방식으로 수정을 해서 아래와 같이 적용해서 문제가 해결된 것을 확인했다.
Text="{Binding Data.ScaleEdit, Source={StaticResource proxy}, UpdateSourceTrigger=PropertyChanged, StringFormat={}{##.##}}" |
Binding한 ScaleEdit은 float 변수이다.
LIST