값 변환기를 사용하여 문자열 접두사를 반환 할 수 있습니다.
class PrefixValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string s = value.ToString();
int prefixLength;
if (!int.TryParse(parameter.ToString(), out prefixLength) ||
s.Length <= prefixLength)
{
return s;
}
return s.Substring(0, prefixLength);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
그리고 XAML에서 :
<Window.Resources>
...
<local:PrefixValueConverter x:Key="PrefixValueConverter"/>
</Window.Resources>
...
...{Binding Path=TheProperty, Converter={StaticResource PrefixValueConverter},
ConverterParameter=1}...
출처
https://stackoverflow.com/questions/2006195