By inserting data generated in Behind code through the model without having to DISPLAY in the view, is it possible?

Asked

Viewed 23 times

1

Look I’ll start by saying that I know what I’m trying to do is break a taboo of the MVVM standard, but it is not possible that there is no other way to do this, it is common to have q create new variables in the background of the application and have q send them to the server.

Being very direct I’m using a timpespan that works by an Eventhandler to be my timer that is displayed for a period of time, to be easier to insert this value on the server I thought to make a time converter that transforms everything in minute and sends it to the server as Int32 every minute, through another timespan that is activated every minute:

Converttemp.Cs

public static int ConvertTemp(string value)
       {
           DateTime temp = DateTime.ParseExact(value, "HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
           int val = temp.Hour*60 ;

           return val + temp.Minute;
       }

From that moment on I have the existence of a new variable in the code Behind of xaml.Cs (view), the same is contextualized in . Cs(Viewmodel) but the only way to insert into the server I found (I’m not sure if it’s really the only way) was through Binding (data association) via View, this means that in order to have the server sent by the Model I have to create an element in the view, associate it via Binding with the variable and enable the sending of data through Mode=Twoways. Stayed like this:

XAML

  <TextBlock Text="{Binding US_01TIM_CPM_01, Mode=TwoWay}" Visibility="Hidden" x:Name="TIM_CPM_01"/>

I even tried to use the converter={staticResouce ConvertTemp} however it did not work (I did all the role of override and : ValueConverter<string, int> in the Convertemp class and did not roll) and I had to make the call in the Event Handler every minute so:

 private void t_Minute(object sender, EventArgs e) {
            //Binding binding = new Binding("Text");
            //binding.Source = TIM_COP_01.Text;
            //TIM_CPM_01.SetBinding(TextBlock.TextProperty, binding);
            TIM_CPM_01.Text = ""+Data.ConvertTemp.ConvertT(TIM_COP_01.Text);
        }

I’ll leave the comments for you to have idea of what I’ve tried, I thank you already!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.