error in creating an instance of class in xaml and setting its properties

自作多情 提交于 2019-12-25 16:46:40

问题


i need to create an instance of a class with two property that would be used as converter parameter of a binding. the class is as below:

public class UnitQuantityBindClass:DependencyObject
{
    public static readonly DependencyProperty QuantityProperty = DependencyProperty.Register(
        "Quantity", typeof(EQuantities), typeof(UnitQuantityBindClass));

    public EQuantities Quantity
    {

        get
        {
            return (EQuantities) GetValue(QuantityProperty);
        }
        set { SetValue(QuantityProperty, value); }
    }

    public static readonly DependencyProperty UnitProperty = DependencyProperty.Register(
        "Unit", typeof(Enum), typeof(UnitQuantityBindClass));

    public Enum Unit
    {
        get { return (Enum)GetValue(UnitProperty); }
        set { SetValue(UnitProperty, value); }
    }
}

the xaml code is as below also:

<textboxunitconvertor:TextBoxUnitConvertor Name="gasDensityValueControl" InstantaneousConvert="True" Margin="96,163,0,0" IsEnabled="{Binding ElementName=chkGas,Path=IsChecked}" QuantityBind="{Binding _FluidBlackOilClass.SGGas_SC.Quantity , RelativeSource={RelativeSource AncestorType=Window}, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"  Width="206" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top">
     <textboxunitconvertor:TextBoxUnitConvertor.TextBoxText>
        <Binding Path="_FluidBlackOilClass.SGGas_SC.Value" RelativeSource="{RelativeSource AncestorType=Window}" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" Converter="{StaticResource ValueStorageForUnitConverter}">
                 <Binding.ConverterParameter>
                     <classes:UnitQuantityBindClass Quantity="{Binding ElementName=gasDensityValueControl,Converter={StaticResource DummyConverter} ,Path=_Quantity,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, PresentationTraceSources.TraceLevel=High}" Unit="{Binding ElementName=gasDensityValueControl,Path=_CurrentUnitEnum,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"></classes:UnitQuantityBindClass>    
                 </Binding.ConverterParameter>
         </Binding>
     </textboxunitconvertor:TextBoxUnitConvertor.TextBoxText>    
     <textboxunitconvertor:TextBoxUnitConvertor.CurrentUnitEnumBind>
         <Binding Source="{StaticResource CurrentFlowProWorkingClass}" Path="currentFlowProWorkingClass.ProjectUnitSystem" UpdateSourceTrigger="PropertyChanged" Mode="OneTime">
            <Binding.ConverterParameter>
                 <classes:UnitQuantityBindClass Quantity="{Binding ElementName=gasDensityValueControl,Path=_Quantity,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Unit="{Binding ElementName=gasDensityValueControl,Path=_CurrentUnitEnum,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"></classes:UnitQuantityBindClass>
             </Binding.ConverterParameter>
         </Binding>
     </textboxunitconvertor:TextBoxUnitConvertor.CurrentUnitEnumBind>
</textboxunitconvertor:TextBoxUnitConvertor>   

but the create class is empty and the Unit and quantity properties does not bind. why?

来源:https://stackoverflow.com/questions/41077119/error-in-creating-an-instance-of-class-in-xaml-and-setting-its-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!