我有一个SilverLight项目,我希望文本框中有一个占位符(水印)。 为此,我通过查看this link创建了一个新的行为。
定义类的名称空间:
namespace SignificantDigits.MediWatch.ReceptionistApp.SL
{
public class Watermark : Behavior<TextBox>
{
//Members
}
}
在我的silverlight控件(XAML)中,我使用过这种行为:
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Interactivity="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:sl="clr-namespace:SignificantDigits.MediWatch.ReceptionistApp.SL"
Width="950" Name="OpdRowStackPanel" Background="Transparent" Height="55" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="737*"/>
<ColumnDefinition Width="213*"/>
</Grid.ColumnDefinitions>
<TextBlock Name="SerialNoTextBlock" HorizontalAlignment="Left" Margin="10,15,0,0" TextWrapping="Wrap" Text="1." VerticalAlignment="Top" Style="{StaticResource CustomLabel}"/>
<TextBox Name="MedicineName" HorizontalAlignment="Left" Height="29" Margin="41,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="190" Style="{StaticResource CustomTextBoxStyle}">
<Interactivity:Interaction.Behaviors> //Behaviour used here
<sl:Watermark Text="Medicine Name" Foreground="DarkGray"/>
</Interactivity:Interaction.Behaviors>
</TextBox>
这个编译没有任何错误。但是当我运行它时,抛出以下异常 -
类型&#39;水印&#39;找不到因为 &#39; CLR的命名空间:SignificantDigits.MediWatch.ReceptionistApp.SL&#39;是一个 未命名空间。 [行:13位置:59]
我做错了什么?
答案 0 :(得分:0)
通过在XAML中提及程序集名称以及命名空间名称来解决这个问题。
xmlns:sl="clr-namespace:SignificantDigits.MediWatch.ReceptionistApp.SL;assembly=SignificantDigits.MediWatch.ReceptionistApp.SL"