C# 如何消除xaml WP8.1中的名称空间错误

C# 如何消除xaml WP8.1中的名称空间错误,c#,wpf,xaml,mvvm,windows-phone-8.1,C#,Wpf,Xaml,Mvvm,Windows Phone 8.1,我正在使用Windows Phone 8.1 projet,目前在使用BooleanToVisibility转换器时遇到问题 以下是转换器本身: public class BooleanToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { if (!(va

我正在使用Windows Phone 8.1 projet,目前在使用BooleanToVisibility转换器时遇到问题

以下是转换器本身:

public class BooleanToVisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        if (!(value is bool))
            return Visibility.Collapsed;
        bool objValue = (bool)value;
        if (objValue)
        {
            return Visibility.Visible;
        }
        return Visibility.Collapsed;

    }
    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        throw new NotImplementedException();
    }
}
这是我的Xaml:

<Page
x:Class="CityBox.MainPage"
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"
xmlns:views="using:CityBox.Views"
xmlns:converters="using:CityBox.Converters"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
DataContext="{Binding Main, Source={StaticResource Locator}}"
x:Name="MyMainPage">

<Page.Resources>
    <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</Page.Resources>


<Grid>
    <views:DataLoadingView x:Name="DataLoadingView" 
                           Visibility="{Binding LoadingViewVisibility, Converter={StaticResource BooleanToVisibilityConverter}}"/>
    <views:DrawerView  x:Name="DrawerView"  
                       Visibility="{Binding DrawerViewVisibility, Converter={StaticResource BooleanToVisibilityConverter}}" />
</Grid>
</Page>
有一件事我不明白,我认为问题可能来自于,在资源(在xaml中)中,我收到某种警告,告诉我“BooleantVisibilityConverter”不在指定的名称空间中,这很奇怪,因为它是由resharper自动添加的。我认为这只是VS的一个错误,就像有时会发生一样,但当我更改布尔值时,它不起作用

希望我足够精确,你能帮助我! 提前感谢,, 纪尧姆

编辑:我刚刚运行了一些测试,这里有一些有趣的东西:

    <Grid>
    <!--<TextBlock Text="Test1" Visibility="{Binding Test2, Converter={StaticResource BooleanToVisibilityConverter}}"/>
    <TextBlock Text="Test2" Visibility="{Binding Test1, Converter={StaticResource BooleanToVisibilityConverter}}"/>-->
    <views:LoadingView Visibility="{Binding Test2, Converter={StaticResource BooleanToVisibilityConverter}}"/>
        <views:DrawerView Visibility="{Binding Test1, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</Grid>

如果我取消注释这两个文本块并注释我的两个视图,那么它就工作了。 如果我用另一种方式做,它就不会。在simple中的每个视图中都放置一个文本块,上面写着“Loading”和“Drawer”。如果我取消对这两个视图的注释,并试图通过将bool设置为false来隐藏其中一个视图,那么这两个视图在屏幕上是可见的。如果我用两个文本框就不会发生这种情况

将xml更改为:

<Page
x:Class="CityBox.MainPage"
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"
xmlns:views="using:CityBox.Views"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
DataContext="{Binding Main, Source={StaticResource Locator}}"
x:Name="MyMainPage">

<Page.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</Page.Resources>

<Grid>
<views:DataLoadingView x:Name="DataLoadingView" 
                       Visibility="{Binding LoadingViewVisibility, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<views:DrawerView  x:Name="DrawerView"  
                   Visibility="{Binding DrawerViewVisibility, Converter={StaticResource BooleanToVisibilityConverter}}" />


将转换器更改为转换器即使在更改之后,我仍然会有相同的错误。如果我没有放置“转换器:”则visual studio在静态资源中会出现一个真正的错误,即“无效资源:预期的IValueConverter”我没有wp8。但在wpf中,如果我将
xmlns:converters=“clr namespace:CityBox.converters”
放入并编译它,问题就会消失。@bott尝试了您的解决方案,结果与上面相同,真正的编译错误请看一看。同样的问题。这是一种错误。我通过重新编译或清理解决方案来修复它,然后再次重新编译。如果它不起作用,请尝试@bottusi链接中给出的解决方案,我不知道。那么这会影响警告吗?如果是这样,我想你的问题出在别的地方了@肉毒杆菌
<Page
x:Class="CityBox.MainPage"
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"
xmlns:views="using:CityBox.Views"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
DataContext="{Binding Main, Source={StaticResource Locator}}"
x:Name="MyMainPage">

<Page.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</Page.Resources>

<Grid>
<views:DataLoadingView x:Name="DataLoadingView" 
                       Visibility="{Binding LoadingViewVisibility, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<views:DrawerView  x:Name="DrawerView"  
                   Visibility="{Binding DrawerViewVisibility, Converter={StaticResource BooleanToVisibilityConverter}}" />