我正在尝试修剪 silverlight 自定义控件组合框的选定值。我发现使用 IValueConverter 类应该是要走的路。所以我在我的图书馆里创造了这个
public class StringTrimmer : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.ToString().Trim();
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
这是组合框的 xaml
<UserControl x:Class="SilverlightControlLibrary.SilverlightComboBoxControl"
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"
mc:Ignorable="d" Height="25" Width="122">
<ComboBox Height="23" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120"
Margin="0,0,0,0" Name="ModuleIDFilterCB"
ItemsSource="{Binding Path=Screen.LicenseModuleIDs, Mode=TwoWay}"
DisplayMemberPath="LicenseModuleName"
SelectedItem="{Binding Screen.bufferProp, Converter={StaticResource StringTrimmer},Mode=TwoWay}"
/>
</UserControl>
除了无法解析 SelectedItem 的资源“StringTrimmer”。我尝试将此引用添加到 xaml,但它仍然没有工作。
xmlns:c="clr-namespace:SilverlightControlLibrary"
编辑:我也试过这个
xmlns:custom="clr-namespace:SilverlightControlLibrary"
随着
SelectedItem="{Binding Screen.bufferProp, Converter= {StaticResource custom:StringTrimmer}, Mode=TwoWay}"
无济于事。。
这个http://msdn.microsoft.com/en-us/library/cc189061%28v=vs.95%29.aspx是微软对 XAML 命名空间的看法
这个http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.convert.aspx用于 IValueConverter
我哪里错了?