8,757
社区成员
发帖
与我相关
我的任务
分享
<UserControl.Resources>
<local:NumberConverter x:Key="NumberConverter" />
</UserControl.Resources>
namespace CommonWPFApp
{
public class TestConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
<Window x:Class="CommonWPFApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CommonWPFApp"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:TestConverter x:Key="TestConverter"></local:TestConverter>
</Window.Resources>
</Window>

public class NumberConverter : IValueConverter
{
static String zhNum = "〇一二三四五六七八九";
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
String s = "";
foreach (Char c in value.ToString())
if (c >= '0' && c <= '9')
s += zhNum[c - '0'];
return s;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}