본문 바로가기
WPF

WPF TextBox에 float 바인딩 해서 소수점이 입력되지 않는 문제

by leo21c 2021. 7. 9.
SMALL

WPF를 이용해서 TextBox에 Float이나 Double 값을 입력 하려고 했는데 소스점이 입력되지 않는 문제가 확인되었다.

이것 저것 검색한 결과 아래와 같은 정보를 찾아서 수정을 진행했다.

 

https://stackoverflow.com/questions/14600842/bind-textbox-to-float-value-unable-to-input-dot-comma/14600905#14600905

 

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>

위와 같은 방식으로 수정을 해서 아래와 같이 적용해서 문제가 해결된 것을 확인했다.

Text="{Binding Data.ScaleEdit, Source={StaticResource proxy}, 
         UpdateSourceTrigger=PropertyChanged, StringFormat={}{##.##}}"

Binding한 ScaleEdit은 float 변수이다.

LIST

'WPF' 카테고리의 다른 글

RadTreeListView Example  (0) 2021.09.02
WPF MVVM TextBox KeyDown Event  (0) 2021.07.20
WPF 체크박스 글자 색 변경  (0) 2021.06.07
WPF 동적으로 Margin 변경  (0) 2021.06.07
Combobox SelectionChanged 호출시 SelectedItem 확인 방법  (0) 2021.05.10