我有一个测试Multibinding的项目。 我想结合从TextBox2中的数据和textBox3到textBox1中。 我试了一次又一次,但仍然得到了错误。
XAML:
<Window x:Class="Test_Multibiding.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="621"
xmlns:c="clr-namespace:Test_Multibiding">
<Window.Resources>
<c:StringFormatConverter x:Key="StrConverter"/>
</Window.Resources>
<Grid>
<TextBox TextWrapping="Wrap" AcceptsReturn="True" Height="269" HorizontalAlignment="Left" Margin="376,22,0,0" Name="textBox1" VerticalAlignment="Top" Width="211" >
<TextBox.Text>
<MultiBinding Converter="{StaticResource StrConverter}" StringFormat="test {0} test {1} blabla">
<Binding ElementName="textBox2" Path="Text"/>
<Binding ElementName="textBox3" Path="Text"/>
</MultiBinding>
</TextBox.Text>
</TextBox>
<TextBox Height="40" HorizontalAlignment="Left" Name="textBox2" VerticalAlignment="Top" Width="222"/>
<TextBox Height="40" HorizontalAlignment="Left" Name="textBox3" VerticalAlignment="Top" Width="222"/>
</Grid>
主窗口
namespace Test_Multibiding
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public class StringFormatConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
return string.Format(parameter.ToString(), values);
}
public object[] ConvertBack(object value, Type[] targetTypes,
object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException("Cannot convert back");
}
}
}
}
而我得到的错误:
The tag 'StringFormatConverter' does not exist in XML namespace 'clr-namespace:Test_Multibiding'.
所以,请告诉我在哪里的问题呢?