There is a function created from the core/business layer, which performs calculations and the value of the result needs to appear in a textbox of the view...
This is the text box:
<TextBlock Text="{Binding Source={StaticResource ResourceWrapper},
Path=RecursosControles.EtiquetaValor,
ValidatesOnNotifyDataErrors=False}" VerticalAlignment="Center" Grid.Row="4" />
in my action method where you called the function it looks like this:
private void CalcularAction(object obj)
{
if (!string.IsNullOrEmpty(this.DocumentoID))
{// aca enviar al textbox del view txtValor.text =
CalcularConceptoPPA(this.DocumentoID, this.concepto.DiasMes, this.concepto.DiasAtraso, this.concepto.Porcentaje, this.concepto.TipoPPA, this.concepto.TCRM);
}//.... demas codigo
UPDATE this method calls the action to the service but does not bring the value
private void CalcularConceptoPPA(string conceptoIDConceptoSTN, int diasMes, int DiasAtraso, double Porcentaje, int tipoPpa, decimal TCRM)
{
App.Current.ServicioCalculos.CalcularConceptoPPA(conceptoIDConceptoSTN, diasMes, DiasAtraso, Porcentaje, tipoPpa, TCRM,
Calculation =>
{
if (Calculation.HasError)
{
this.RiaCallError = Calculation.Error.Message;
Calculation.MarkErrorAsHandled();
}
if (Calculation.IsComplete)
{
CalcularConceptoPPA_Complete(Calculation.Value);
}
}, null);
}
The function in the business layer is defined like this:
public decimal CalcularConceptoPPA(string conceptoIDConceptoSTN, int diasMes, int DiasAtraso, double Porcentaje, int tipoPpa, decimal TCRM)
{
if (String.IsNullOrEmpty(conceptoIDConceptoSTN))
{
return 0;
}
try
I'm new to wpf, any help is appreciated
It's supposed to be if you're using ViewModel or View then you're following the MVVM pattern. The matter, to understand, is more or less like this:
You have a window (view) with a
TextBlock
and a SEPARATE class that is the ViewModel where you do the calculations, because in the window, above you have to add the namespace of the ViewModel, something like this:With that your window already knows where it has to get the data it shows. And the TextBlock will be something like this:
There the TextBlock already knows that it has to show the "Result" value that is in the ViewModel that you defined above, then, that "Result" variable would be one
String
that is in the ViewModel (or aInt
, you see that), something like this :And when you press a button in the VIEW you should call, through an ICommand, your calculation method, which should, in turn, set the Property "Result"
That would be enough, unless you don't know how to use ICommands, but that's for another question, and you must remember to apply INotifyPropertyChanged to communicate changes from the ViewModel to the View... otherwise, even if you do a thousand things, the screen won't do anything.
Edit: I leave you the implementation of INotifyPropertyChanged
And "Result" would look like this:
Now, I'm having a bit of a hard time understanding your implementation because it looks like you're mixing patterns.
And so it becomes more less... If you still have doubts please expand your question a little more and I will gladly improve the answer.
All the best :)