相关疑难解决方法(0)

在文本框中没有填充任何内容时,在mvvm WPF中将null设置为property

我实现了一个文本框,这绑定到一个viewmodel.我填写文本框默认为'100',但如果我将其更改为10,则属性始终设置正确.但是当我删除所有数字时,我希望该属性设置为null.但它只是在没有填充任何内容时设置值.他只保留最后一个值..

这是我的代码,viewmodel + xaml:

public double MaxTime
{
    get
    {
        return maxTime;
    }
    set
    {
        maxTime = value;
        OnPropertyChanged("MaxTime");
        if (SelectedQuestionDropList != null)
        {
            foreach (QuestionCluster cluster in this.Examination.QuestionClusters)
            {
                if (cluster == SelectedQuestionDropList)
                {
                    cluster.MaxTime = value;
                }
            }
        }
    }
}


<TextBox Height="23" 
         Visibility="{Binding Path=VisibleClusterDetails, Converter={StaticResource boolToVis},UpdateSourceTrigger=PropertyChanged}"  
         Text="{Binding Path=MaxTime,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
         HorizontalAlignment="Right" Margin="0,511,601,0" Name="textBox2" 
         VerticalAlignment="Top" Width="120" /> 
Run Code Online (Sandbox Code Playgroud)

wpf null properties mvvm

2
推荐指数
1
解决办法
3506
查看次数

标签 统计

mvvm ×1

null ×1

properties ×1

wpf ×1