xaml分为2种类型:
(1)新建.netcore 项目或者.netframework 项目的WPF 窗体应用程序,
namespace 转换器
{
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return Visibility.Hidden;
}
else
{
if ((bool)value)
return Visibility.Visible;
else
return Visibility.Hidden;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
可以直接添加命名空间: xmlns:local="clr-namespace:转换器",然后静态引用是不会报错的。
<TextBlock Text="{Binding ElementName=t1,Path=Text,Cnotallow={StaticResource dis}}" Fnotallow="50"></TextBlock>
(2)新建的项目[1]是C# 类库,然后添加了用户控件usercontroller.xaml窗体,在这直接引用就会提示找不到转换器类的资源,或者错误提示转换器的dll无法加载。
解决办法:
再新建一个类库项目[2],将转换器类移动到这个类库中,然后生成[2].dll文件。在刚才的xaml项目[1]中添加引用[2].dll,然后在项目[1]重新生成即可消除错误提示。