我在Windows Phone 8.1上开发了应用程序.我的几个页面都有自定义转换器; 例如:
using System;
using System.Globalization;
using Windows.UI.Xaml.Data;
namespace XXXXX.Model.Converters
{
public sealed class DateTimeToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
var date = (DateTime)value;
return date.ToString("g", new CultureInfo("it-IT"));
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在XAML我有:
<Page
x:Class="XXXXX.Views.VehiclesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="using:XXXXX.Model.Converters"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Foreground="{StaticResource PhoneForegroundBrush}">
<Page.Resources>
<converters:DateTimeToStringConverter x:Key="DateTimeToStringConverter" />
<converters:StringFormatConverter x:Key="StringFormatConverter" />
</Page.Resources>
Run Code Online (Sandbox Code Playgroud)
并以这种方式使用它:
<TextBlock …Run Code Online (Sandbox Code Playgroud)