2011-04-10 6 views
1

double의 최하위 값이 0이 아닌 경우 컨트롤을 표시하는 정도에 따라 다른 정밀도로 렌더링됩니다.TextBox 또는 Label (WPF)에 표시된 경우 .NET double이 다르게 렌더링됩니다.

필자의 경우 TextBox와 Label을 사용해 보았습니다. ToString은 TextBox와 같은 결과를 제공합니다. 그러나 Label 컨트롤은 더 높은 정밀도를 보여줍니다.

여기 예입니다 (그냥 의미를 알기 위해 엄지 손가락을 드래그) :

<Window x:Class="SliderTest.SliderTestWindow" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Title="SliderTestWindow" Height="300" Width="300"> 
<StackPanel> 
    <Slider Name="slider" TickFrequency="0.1" IsSnapToTickEnabled="True" /> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto"/> 
      <ColumnDefinition Width="*"/> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
     </Grid.RowDefinitions> 
     <TextBlock Grid.Row="0" Grid.Column="0">Value</TextBlock> 
     <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding ElementName=slider, Path=Value}" /> 
     <TextBlock Grid.Row="1" Grid.Column="0">Value</TextBlock> 
     <Label Grid.Row="1" Grid.Column="1" Content="{Binding ElementName=slider, Path=Value}" /> 
    </Grid> 
</StackPanel> 

이유는 각 컨트롤의 두 배를 렌더링하는 다른 방법을 사용됩니까?

Label에서 DoubleBox를 TextBox에서 렌더링하는 것처럼 렌더링하려면 어떻게해야합니까?

답변

4

바인딩에 대한 형식 문자열을 제공 할 수 있습니다. 통화 포매터를 사용하는 예입니다

<TextBox Text="{Binding Path=Double, StringFormat=F3}"/> 
<TextBox Text="{Binding Path=Double, StringFormat=Amount: {0:C}}"/> 
<TextBox Text="{Binding Path=Double, StringFormat=Amount: \{0:C\}}"/> 
<TextBox> 
    <TextBox.Text> 
    <Binding Path="Double" StringFormat="{}{0:C}"/> 
    </TextBox.Text> 
</TextBox> 

출처 : http://blogs.msdn.com/b/llobo/archive/2008/05/19/wpf-3-5-sp1-feature-stringformat.aspx

문자열 형식 도움말 : http://alexonasp.net/samples/stringformatting/

관련 문제