我实现了一个文本框,这绑定到一个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)