Answer the question
In order to leave comments, you need to log in
Why doesn't binding a result to the Content property of a button in WPF work?
Good afternoon, comrades, help me deal with the following question. There is such a form:
In theory, it should display the result of some function action in the Content of the button. For all fields, the following binding is made:
<TextBox Text="{Binding Path=DataModel.A0, UpdateSourceTrigger=PropertyChanged}" Name="dA0" Grid.Row="0" Margin="2,2,2,2" Grid.Column="1"/>
<TextBox Text="{Binding Path=DataModel.B0, UpdateSourceTrigger=PropertyChanged}" Name="dB0" Grid.Row="1" Margin="2,2,2,2" Grid.Column="1"/>
<TextBox Text="{Binding Path=DataModel.L, UpdateSourceTrigger=PropertyChanged}" Name="dl" Grid.Row="2" Margin="2,2,2,2" Grid.Column="1"/>
<Button Command="{Binding DichotomyCmd}" Content="{Binding Path=DataModel.Ans, UpdateSourceTrigger=PropertyChanged}" Name="dBtn" Height="20" IsEnabled="True" Margin="2,2,2,2" Grid.Row="3" Grid.ColumnSpan="2"/>
public ICommand DichotomyCmd
{
get
{
if (_dichotomyCmd == null)
_dichotomyCmd = new RelayCommand(ExecuteDichotomyCommand, CanExecuteDichotomyCmd);
return _dichotomyCmd;
}
}
public void ExecuteDichotomyCommand(object parameter)
{
DataModel.Ans = Dichotomy(DataModel.A0, DataModel.B0, DataModel.L).ToString();
DataModel = null;
}
public bool CanExecuteDichotomyCmd(object parameter)
{
if (DataModel.L == 0 && DataModel.N == 0)
return false;
else
return true;
}
class DataModel
{
public double A0 { get; set; }
public double B0 { get; set; }
public int N { get; set; }
public double L { get; set; }
public string Ans { get; set; }
public string _L { get; set; }
public DataModel()
{
}
public DataModel(double a0, double b0, int n)
{
this.A0 = a0;
this.B0 = b0;
this.N = N;
}
public DataModel(double a0, double b0, float l)
{
this.A0 = a0;
this.B0 = b0;
this.L = l;
}
}
Answer the question
In order to leave comments, you need to log in
1) DataModel inherit from INotifyPropertyChanged
2) why nullify DataModel = null; object reference is lost
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question