运行时错误:找不到InverseBooleanConverter

社交网络

我在尝试遵循以下建议时遇到问题:如何在WPF中绑定反布尔属性?

当我与ResourceDictionary一起使用时,它会给出运行时错误。找不到InverseBooleanConverter。

XMAL如下:

<UserControl x:Class="SMTF.MasterDataView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SMTF" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="466" d:DesignWidth="483">
<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="../AppResource.xaml" />
            <ResourceDictionary Source="../DefaultStyle.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>
    <Grid>
    <StackPanel  HorizontalAlignment="Left" Margin="200,12,0,0" Name="stkMain" VerticalAlignment="Top" >
        <Grid Margin="4">
            <ContentControl Visibility="{Binding IsChecked, ElementName=VisibilityToggle, Converter={StaticResource InverseBooleanConverter}}" >
                <Border Grid.Column="2" Style="{StaticResource MainBorderStyle}">
                    <HeaderedContentControl   Content="{Binding Path=WorkspaceView}" ContentTemplate="{StaticResource WorkspacesTemplate}" Header="View" Style="{StaticResource MainHCCStyle}"/>
                </Border>
            </ContentControl>
        </Grid>
        <Grid DockPanel.Dock="Bottom" Margin="0,2,4,2">
            <TextBlock HorizontalAlignment="Right">

               <ToggleButton  x:Name="VisibilityToggle" Focusable="False" Style="{StaticResource SMToggle}"  Command ="{Binding ShowNew}" >

                </ToggleButton>
               <!--<ToggleButton x:Name="VisibilityToggle"   Background="Transparent" Command ="{Binding ShowNew}" >
                     <Image Source="/Image/Add.png"  Width="24" />
                </ToggleButton>-->
            </TextBlock>

        </Grid>

        <Grid Margin="4">
            <ContentControl Visibility="{Binding IsChecked, ElementName=VisibilityToggle, Converter={StaticResource BoolToVisibility}}" >
            <Border Grid.Column="2" Style="{StaticResource MainBorderStyle}">
                <HeaderedContentControl  Content="{Binding Path=WorkspaceEdit}" ContentTemplate="{StaticResource WorkspacesTemplate}" Header="Configure" Style="{StaticResource MainHCCStyle}"/>
            </Border>
            </ContentControl>
        </Grid>
    </StackPanel>

</Grid>
</UserControl>

我正在使用链接中提供的相同代码。即:

[ValueConversion(typeof(bool), typeof(bool))]
public class InverseBooleanConverter: IValueConverter
{
    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter,
        System.Globalization.CultureInfo culture)
    {
        if (targetType != typeof(bool))
            throw new InvalidOperationException("The target must be a boolean");

        return !(bool)value;
    }

    public object ConvertBack(object value, Type targetType, object parameter,
        System.Globalization.CultureInfo culture)
    {
        throw new NotSupportedException();
    }

    #endregion
}

在AppResource XML中

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:vm="clr-namespace:SMTF">
 <vm:InverseBooleanConverter x:Key="InverseBoolToVisibility" /> 
 .....
 .....
</ResourceDictionary>

在此先感谢NS

尼丁

您使用的密钥不正确。InverseBoolToVisibility使用InverseBooleanConverter作为键时,资源键为

更改资源密钥以将正确的资源引用为

<ContentControl Visibility="{Binding IsChecked, ElementName=VisibilityToggle, Converter={StaticResource InverseBoolToVisibility}}" >

同样,您对convereter的实现是错误的。如果要更改基于布尔逆值的可见性,请将转换器代码更新为:

public class InverseBooleanConverter: IValueConverter
{
    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter,
        System.Globalization.CultureInfo culture)
    {
        if (targetType != typeof(Visibility))
            throw new InvalidOperationException("The target must be a boolean");

        if(!(bool)value)
        {
            return Visibility.Visible;
        }
        return Visibility.Collapsed;
    }

    public object ConvertBack(object value, Type targetType, object parameter,
        System.Globalization.CultureInfo culture)
    {
        throw new NotSupportedException();
    }

    #endregion
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

运行时错误76找不到路径

来自分类Dev

找不到列[0]运行时错误

来自分类Dev

找不到指向Parcelable的运行时错误NoClassDefFoundError

来自分类Dev

从Fatjar运行时找不到MessageBodyWriter错误

来自分类Dev

运行时Docker映像错误:找不到文件

来自分类Dev

剃刀引擎运行时错误-找不到程序集

来自分类Dev

找不到列[0]运行时错误

来自分类Dev

运行时错误76找不到路径

来自分类Dev

“运行时错误'1004'-找不到文件”

来自分类Dev

引用的运行时错误找不到excel文件

来自分类Dev

运行时错误 76:找不到路径

来自分类Dev

离子 => 运行时错误:找不到模块“。”

来自分类Dev

如何解决运行时错误:找不到graphframes

来自分类Dev

找不到运行时目录

来自分类Dev

以sudo运行时找不到命令

来自分类Dev

VBA错误运行时13错误类型不匹配找不到发生的位置

来自分类Dev

如何处理该错误:找不到运行时错误'53'文件

来自分类Dev

运行时错误PowerMock + Mockito:在类路径中找不到ProxyFrameworkImpl

来自分类Dev

Gitlab CI安装程序错误-找不到JavaScript运行时

来自分类Dev

Docker错误:从Win10运行时找不到或不存在容器命令

来自分类Dev

运行时错误“找不到路径的一部分”

来自分类Dev

错误:在TextPad中运行时找不到或加载主类

来自分类Dev

运行时错误2465找不到带有alter column的字段'| 1'

来自分类Dev

Azure应用服务抛出运行时错误:找不到程序集

来自分类Dev

DAG使用ExternalTaskSensor运行时显示错误“找不到env_var.json”

来自分类Dev

未处理的运行时错误ReferenceError:找不到变量:Safari上的ResizeObserver

来自分类Dev

UVA在线法官返回我找不到的运行时错误

来自分类Dev

如何在Tycho中解决运行时错误“找不到条目”?

来自分类Dev

运行时错误1004:Excel VBA找不到要打开的文件

Related 相关文章

  1. 1

    运行时错误76找不到路径

  2. 2

    找不到列[0]运行时错误

  3. 3

    找不到指向Parcelable的运行时错误NoClassDefFoundError

  4. 4

    从Fatjar运行时找不到MessageBodyWriter错误

  5. 5

    运行时Docker映像错误:找不到文件

  6. 6

    剃刀引擎运行时错误-找不到程序集

  7. 7

    找不到列[0]运行时错误

  8. 8

    运行时错误76找不到路径

  9. 9

    “运行时错误'1004'-找不到文件”

  10. 10

    引用的运行时错误找不到excel文件

  11. 11

    运行时错误 76:找不到路径

  12. 12

    离子 => 运行时错误:找不到模块“。”

  13. 13

    如何解决运行时错误:找不到graphframes

  14. 14

    找不到运行时目录

  15. 15

    以sudo运行时找不到命令

  16. 16

    VBA错误运行时13错误类型不匹配找不到发生的位置

  17. 17

    如何处理该错误:找不到运行时错误'53'文件

  18. 18

    运行时错误PowerMock + Mockito:在类路径中找不到ProxyFrameworkImpl

  19. 19

    Gitlab CI安装程序错误-找不到JavaScript运行时

  20. 20

    Docker错误:从Win10运行时找不到或不存在容器命令

  21. 21

    运行时错误“找不到路径的一部分”

  22. 22

    错误:在TextPad中运行时找不到或加载主类

  23. 23

    运行时错误2465找不到带有alter column的字段'| 1'

  24. 24

    Azure应用服务抛出运行时错误:找不到程序集

  25. 25

    DAG使用ExternalTaskSensor运行时显示错误“找不到env_var.json”

  26. 26

    未处理的运行时错误ReferenceError:找不到变量:Safari上的ResizeObserver

  27. 27

    UVA在线法官返回我找不到的运行时错误

  28. 28

    如何在Tycho中解决运行时错误“找不到条目”?

  29. 29

    运行时错误1004:Excel VBA找不到要打开的文件

热门标签

归档