[英]How to get rid of the namespace error in xaml WP8.1
I'm working on a Windows Phone 8.1 projet and i'm currently having issues using my BooleanToVisibility Converter. 我正在使用Windows Phone 8.1投影机,并且当前在使用BooleanToVisibility Converter时遇到问题。
Here is the Converter itself: 这是转换器本身:
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();
}
}
Here is my Xaml: 这是我的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>
And finaly my booleans from my ViewModel: 最后从我的ViewModel中获取我的布尔值:
private bool _loadingViewVisibility;
private bool _drawerViewVisibility;
public bool LoadingViewVisibility
{
get { return _loadingViewVisibility;}
set
{
_loadingViewVisibility = value;
RaisePropertyChanged("LoadingViewVisibility");
}
}
public bool DrawerViewVisibility
{
get { return _drawerViewVisibility; }
set
{
_drawerViewVisibility = value;
RaisePropertyChanged("DrawerViewVisibility");
}
}
One thing that i don't understand and i think the problem might come from is that in the Resource (in the xaml), i have some kind of warning telling me that "BooleanToVisibilityConverter" is not in the specified namespace which is weird because it was automatically added by resharper. 我不明白的一件事是问题可能来自资源(在xaml中),我有某种警告告诉我“ BooleanToVisibilityConverter”不在指定的命名空间中,这很奇怪,因为它由reshaper自动添加。 I thought it was just an error from VS like it happends sometimes but it doesn't work when i change the values of my bools.
我以为这只是VS的一个错误,有时会发生,但是当我更改布尔值时它不起作用。
Hope i was precise enough for you to help me! 希望我足够精确,能为您提供帮助! thanks in advance, Guillaume.
预先感谢,纪尧姆。
EDIT : I just ran some tests and here is something interesting: 编辑:我只是运行了一些测试,这是有趣的事情:
<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>
If i uncomment the two textblocks and comment my two views then it works. 如果我取消注释这两个文本块并注释我的两个视图,那么它将起作用。 If i do it th other way arounds, it doesnt.
如果我以其他方式这样做,它不会。 in each of those views in simple put a Textblock saying "Loading" and "Drawer".
在每个视图中,简单地放置一个Textblock,上面写着“ Loading”和“ Drawer”。 in the case where i uncomment the two views and try to hide one by setting a bool to false, those two views are visible on the screen.
在我取消注释两个视图并尝试通过将bool设置为false来隐藏一个视图的情况下,这两个视图在屏幕上可见。 Which doesn't happen if i do it with the two textboxes !!
如果我用两个文本框来做,那不会发生!
Change your xml to: 将您的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}}" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.