资源'BoolToInvertedBoolConverter'无法解析

时间:2018-10-01 06:03:40

标签: c# xaml silverlight ivalueconverter

我是Silverlight开发的新手。在我的活动期间,我遇到了一个错误,该错误在我的帖子标题中提到。我的主要目的是单击按钮时弹出日期选择器。

 <ToggleButton  x:Name="TogglePopupButton" HorizontalAlignment="Right" Height="26" VerticalAlignment="Center" Grid.Column="1" Style="{StaticResource ToolIconToggleButtonStyle}" Width="26" 
               IsEnabled="{Binding ElementName=ToggledPopup, Path=IsOpen,Converter={StaticResource BoolToInvertedBoolConverter}}">

这是.xaml

<UserControl
<xmlns:local="clr-namespace:US.Payment.Web.Modules.PaymentMachine.Utils">
<UserControl.Resources>
    <US_Payment_Web_Converters:GroupRowHeaderVisibilityConverter x:Key="GroupRowHeaderVisibilityConverter"/>
    <viewModel:ImportUSPViewModel x:Name="ViewModel"/>
    <local:AmountValuesConverter x:Name="AmountConverter"/>
    <local:BackgroundConverter x:Key="BackgroundConverter" />
    <local:BoolToInvertedBoolConverter  x:Key="BoolToInvertedBoolConverter " />
    <Style x:Key="CalendarDayButtonStyle1" TargetType="prim:CalendarDayButton">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="prim:CalendarDayButton">
                    <Grid Background= "{Binding Converter={StaticResource BackgroundConverter}, Path=Date}">
                        <ContentControl x:Name="Content" Margin="5,1,5,1" Content="{TemplateBinding Content}" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</UserControl.Resources>

这是BoolToInvertedBoolConverter.cs文件

 public class BoolToInvertedBoolConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value is bool)
        {
            bool boolValue = (bool)value;
            return !boolValue;
        }
        else
            return false;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException("ConvertBack() of BoolToInvertedBoolConverter is not implemented");
    }
}

1 个答案:

答案 0 :(得分:1)

问题是,您在声明资源时不小心在x:Key值的和处放置了一个空格字符。删除该字符,它将起作用。

x:Key =“ BoolToInvertedBoolConverter”->末尾有空格,但应该是

x:Key =“ BoolToInvertedBoolConverter”->没有空格。