值不能为空。参数名称:来自 WPF 按钮绑定数据触发器

Value cannot be null. Parameter name: from WPF button binding datatrigger

我今天一直在努力解决这个问题,当我尝试在按钮上绑定数据触发器时,我遇到了这个问题,但我找不到我们的问题。该按钮包含在绑定到数据集的列表视图中。

这是我的按钮代码:

<Button
                    Grid.Row="1"
                    Grid.Column="0"
                    Click="BtnAddToCart_Click" 
                    MinWidth="230">
                        <Button.Style>

                            <Style TargetType="{x:Type Button}">

                                <Setter Property="Visibility" Value="Hidden"/>
                                <Setter Property="Margin" Value="7,5,0,0"/>

                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=OrderQty, Converter={StaticResource GreaterThanZero}}" Value="True">
                                        <Setter Property="Visibility" Value="Visible"/>
                                    </DataTrigger>

                                </Style.Triggers>
                            </Style>

                        </Button.Style>
                        <Button.Template>
                            <ControlTemplate>
                                <WrapPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
                                    <WrapPanel.Style>
                                        <Style TargetType="{x:Type WrapPanel}">

                                            <Setter Property="Background" Value="#ec3c42"/>
                                            <Setter Property="TextBlock.Foreground" Value="White"/>
                                            <Style.Triggers>
                                                <Trigger Property="IsMouseOver" Value="True">
                                                    <Setter Property="Background" Value="White"/>
                                                    <Setter Property="Cursor" Value="Hand"></Setter>
                                                    <Setter Property="TextBlock.Foreground"  Value="#ec3c42"></Setter>
                                                </Trigger>

                                            </Style.Triggers>

                                        </Style>
                                    </WrapPanel.Style>
                                    <WrapPanel.Resources>
                                        <Style TargetType="{x:Type TextBlock}">
                                            <Setter Property="Padding" Value="10,10" />
                                            <Setter Property="FontWeight" Value="Bold"/>
                                            <Setter Property="FontSize" Value="15"/>
                                        </Style>

                                    </WrapPanel.Resources>
                                    <TextBlock   VerticalAlignment="Center" HorizontalAlignment="Center" Text="Ajouter aux Commandes"></TextBlock>
                                    <fa:FontAwesome Visibility="Hidden" VerticalAlignment="Center" HorizontalAlignment="Right"  Icon="check">
                                        <fa:FontAwesome.Triggers>
                                            <DataTrigger Binding="{Binding Path=ShowAsChecked}" Value="true">
                                                <Setter Property="Visibility" Value="Visible"></Setter>
                                            </DataTrigger>
                                        </fa:FontAwesome.Triggers>

                                    </fa:FontAwesome>
                                </WrapPanel>
                            </ControlTemplate>
                        </Button.Template>
                    </Button>

当我添加这段代码时,问题似乎发生了:

<fa:FontAwesome.Triggers>
                                        <DataTrigger Binding="{Binding Path=ShowAsChecked}" Value="true">
                                            <Setter Property="Visibility" Value="Visible"></Setter>
                                        </DataTrigger>
                                    </fa:FontAwesome.Triggers>

当我删除触发器时,代码 运行 符合预期。

即使我将它绑定到在不同级别上工作的 属性,它也不起作用。

我尝试将绑定更改为:

Binding="{Binding Path=OrderQty, Converter={StaticResource GreaterThanZero}}

它仍然给我错误。我试图查找一些代码示例,但没有找到有关该问题的任何信息(因为错误很常见,所以很难说出发生了什么)。

尝试

<fa:FontAwesome Visibility="Hidden" VerticalAlignment="Center" HorizontalAlignment="Right" Icon="check">
    <fa:FontAwesome.Style>
            <Style TargetType="fa:FontAwesome">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=ShowAsChecked}" Value="true">
                        <Setter Property="Visibility" Value="Visible"></Setter>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
    </fa:FontAwesome.Style>
</fa:FontAwesome>