【问题标题】:Xamarin: Cannot find the IValueConverterXamarin:找不到 IValueConverter
【发布时间】:2017-02-18 10:27:57
【问题描述】:

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

转换器类是在 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>

【问题讨论】:

  • 在转换器上设置断点检查是否执行
  • 我的转换器的构造函数确实被调用了,但没有调用 Convert 方法
  • 不确定转换器是否在非绑定上下文中工作。您正在申请一个 StaticResource。

标签: xamarin converter resourcedictionary


【解决方案1】:

我改成这个解决了这个问题

{Binding Source={StaticResource lower1_1}, Converter={ ..... –

【讨论】:

    猜你喜欢
    • 2015-06-17
    • 2018-06-17
    • 2022-10-06
    • 1970-01-01
    • 2022-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多