zoukankan      html  css  js  c++  java
  • WPF错误:必须使“Property”具有非 null 值。

    这个问题一般出如今Triggers中Property指定的类型为Nullable。

    解决的方法就是用DataTrigger取代Trigger, 然后用Binding+Converter转换为详细非Null值。

    比方:
    <Style x:Key="DisableStyle" TargetType="Button">
                <Style.Triggers>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding ElementName=ckb1, Path=IsChecked, Converter={StaticResource NullableToBooleanConverter}}" Value="true"></Condition>
                            <Condition Binding="{Binding ElementName=ckb2, Path=IsChecked, Converter={StaticResource NullableToBooleanConverter}}" Value="true"></Condition>
                        </MultiDataTrigger.Conditions>
                        <Setter Property="IsEnabled" Value="False"></Setter>
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>


    NullableToBooleanConverter:
    public object Convert( object value , Type targetType, object parameter, CultureInfo culture )
            {
                Nullable<bool > isCheck = value as Nullable< bool>;
                if (null == isCheck)
                {
                    return false ;
                }
                else
                {
                    return isCheck .Value;
                }
            }
  • 相关阅读:
    HTTP请求报文与响应报文
    RTTI (Run-time type information) in C++
    Advanced C++ | Virtual Copy Constructor
    Virtual Destructor
    Advanced C++ | Virtual Constructor
    What happens when more restrictive access is given to a derived class method in C++?
    Can static functions be virtual in C++?
    Virtual functions in derived classes
    Default arguments and virtual function
    Multiple Inheritance in C++
  • 原文地址:https://www.cnblogs.com/claireyuancy/p/7044090.html
Copyright © 2011-2022 走看看