Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml 在ContentView中声明转换器会导致xamarin表单页为空_Xaml_Xamarin_Xamarin.forms - Fatal编程技术网

Xaml 在ContentView中声明转换器会导致xamarin表单页为空

Xaml 在ContentView中声明转换器会导致xamarin表单页为空,xaml,xamarin,xamarin.forms,Xaml,Xamarin,Xamarin.forms,我正在经历创建一个测试用户控件的过程,该控件将在Xamarin Forms应用程序的页面上使用。 我想将一个主题作为字符串从测试页面传递到控件中,然后根据一些不同的因素(如用户设置和应用程序设置)将其转换为颜色。 然而,一旦我在ContentView中声明了转换器,我的页面就停止渲染,我得到的只是一个空白页面 <?xml version="1.0" encoding="UTF-8"?> <ContentView xmlns="http://xamarin.com/schemas

我正在经历创建一个测试用户控件的过程,该控件将在Xamarin Forms应用程序的页面上使用。 我想将一个主题作为字符串从测试页面传递到控件中,然后根据一些不同的因素(如用户设置和应用程序设置)将其转换为颜色。 然而,一旦我在ContentView中声明了转换器,我的页面就停止渲染,我得到的只是一个空白页面

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="MyProject.UserControls.MyControl"
             xmlns:helpers="clr-namespace:MyProject.Converters"             >
    <ContentView.Resources>
        <helpers:StringToColourConverter x:Key="ColorConverter" />
    </ContentView.Resources>
    <ContentView.Content>
        <StackLayout x:Name="ControlRoot">
            <Label x:Name="PrimaryLabel" Text="{Binding PrimaryText}" />
            <Label x:Name="SecondaryLabel" Text="{Binding SecondaryText}" />
        </StackLayout>
    </ContentView.Content>
</ContentView>

谢谢

您是否按如下方式注册了转换器?换句话说,您是否省略了示例的ResourceDictionary标记?据我所知,他们应该在那里

<ContentView.Resources>
   <ResourceDictionary>
        <helpers:StringToColourConverter x:Key="ColorConverter" />
   </ResourceDictionary>
</ContentView.Resources>

同样,如果这种转换器需要经常注册,你可以考虑在App.xAML中注册它,这样你就不必在需要的地方单独引用它。
<Application.Resources>
    <ResourceDictionary>  
        <helpers:StringToColourConverter x:Key="ColorConverter" />
    </ResourceDictionary>
</Application.Resources>


你的转换器是什么样子的?@yoger:里面是什么并不重要。我已经取出了所有代码,现在刚从转换器返回红色,但它甚至从未被击中。请参见上面的示例!小学生的错误。遗憾的是,没有任何反馈或错误,只是显示了一个空白屏幕。实际上,我在运行代码时遇到了
NullReferenceException
错误。也许你在某个地方发现了错误,所以它没有弹出?
<Application.Resources>
    <ResourceDictionary>  
        <helpers:StringToColourConverter x:Key="ColorConverter" />
    </ResourceDictionary>
</Application.Resources>