0
저는 XAML과 C#을 사용하여 Windows 8.1 Store App에서 작업하고 있습니다.IValueConverter를 사용하는 통화 변환기
2 개의 텍스트 상자를 추가하고 IValueConverter 인터페이스를 구현했습니다. 여기
내 변환기 클래스 코드 XAML 코드 여기<Page.Resources>
<local:ConverterClass x:Key="C_Converter" />
<local:EuroConverterClass x:Key="Euro_Converter" />
<local:YenConverterClass x:Key="Yen_Converter" />
</Page.Resources>
<TextBox Name="PKR_TextBox"
Grid.Row="1"
Grid.Column="2"
Width="450"
Height="50"
FontSize="30"
FontWeight="Bold"
HorizontalAlignment="Left"
VerticalAlignment="Center" />
<TextBox Name="DOLLAR_TextBox"
Grid.Row="2"
Grid.Column="2"
Text="{Binding ElementName=PKR_TextBox, Path=Text, Converter={StaticResource C_Converter}}"
Width="450"
Height="50"
FontSize="30"
FontWeight="Bold"
HorizontalAlignment="Left"
VerticalAlignment="Center" />
입니다 :
class ConverterClass : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
int pkr;
int dollar = 0;
if (Int32.TryParse(value.ToString(), out pkr))
{
dollar = pkr * 0.0099;
}
return dollar;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
I 사용자가 정상적으로 자동으로 PKR 텍스트 상자에 값을 입력하면 실행시에 통화를 변환하려고 USD 텍스트 상자를 업데이트하십시오. 하지만 대신 그것은 "암시 적으로 'double'을 'int'로 변환 할 수 없습니다. 명시 적 변환이 존재합니다 (캐스트가 누락 되었습니까?)"
영어를 배우고 제발 영어를 잊어 버리십시오.
감사합니다 ... 고맙습니다. –