【问题标题】:The Resource 'BoolToInvertedBoolConverter' could not be resolved无法解析资源“BoolToInvertedBoolConverter”
【发布时间】:2019-03-06 05:21:28
【问题描述】:

我是 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");
    }
}

【问题讨论】:

    标签: c# xaml silverlight ivalueconverter


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-30
      • 1970-01-01
      • 1970-01-01
      • 2014-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多