Xamarin:找不到IValueConverter

时间:2016-10-10 03:17:57

标签: xamarin converter resourcedictionary

我尝试使用在Xaml文件中声明的自定义IValueConverter。

Converter Class是在EnglishKeyboard中定义的。转换在下面的xaml内的ResourceDictionary中声明。我试着在下面代码的末尾使用这个转换器

<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:local="clr-namespace:ProjectorRemote" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="ProjectorRemote.EnglishKeyboard"
    x:Name="englishKeyboard">
<ContentView.Resources>
    <ResourceDictionary>

        <local:EnglishKeyboard.StringCaseConverter x:Key="caseConverter">
        </local:EnglishKeyboard.StringCaseConverter>

        <!-- lower 1 characters  -->
        <x:String x:Key="lower_1">q</x:String>
        <x:String x:Key="lower1_2">w</x:String>
        <x:String x:Key="lower1_3">e</x:String>
        <x:String x:Key="lower1_4">r</x:String>         
        <x:String x:Key="lower1_5">t</x:String>
        <x:String x:Key="lower1_6">y</x:String>
        <x:String x:Key="lower1_7">u</x:String>
        <x:String x:Key="lower1_8">i</x:String>
        <x:String x:Key="lower1_9">o</x:String>
        <x:String x:Key="lower1_0">p</x:String>

    </ResourceDictionary>
</ContentView.Resources>
<ContentView.Content>
    <StackLayout 
            Orientation="Vertical"  
            HorizontalOptions="Fill"
            VerticalOptions="End">

        <Grid HorizontalOptions="Center" ColumnSpacing="1">

            **<local:BaseKeyView
                Grid.Column="0" 
                Text="{StaticResource lower1_1, 
                    Converter={StaticResource caseConverter}, 
                    ConverterParameter={Binding IsUpper}}">
            </local:BaseKeyView>** 

它没有错误,但在我改为下面的代码后没有调用转换器

<local:BaseKeyView
                Grid.Column="0" 
                Text="{StaticResource lower1_1, 
                    Converter={StaticResource caseConverter}, 
                    ConverterParameter={Binding IsUpper}}">
            </local:BaseKeyView>

1 个答案:

答案 0 :(得分:1)

我通过更改为

来解决问题
map