41308

Pass data between WPF windows

Question:

I have some code that works in winforms, but not in WPF apparently, the code is as follows: This is set globally:

Private Property avar As Object Public main As MainWindow Public charchoice As Char

And then in the Window Loaded sub, this is placed:

charchoice = main.charchoice

Thing is, the next window doesn't pick up this variable, so how can I make it recognise and use it? Thanks Guys

Nick

Answer1:

I had a similar problem and discovered that you must create a public property in the MainWindow and pass a value to the property.

Please see this <a href="https://stackoverflow.com/questions/6427080/change-a-textboxs-text-value-on-a-usercontrol-from-a-window-in-wpf" rel="nofollow">example</a> from a similar question I posted.

Answer2:

Hey i got same problem when i am going to pass values between two forms. I find its solution using a simple class and Shared property.

First I create a class named with cls_pass_val which is as under:-

Public Class cls_pass_val Private Shared var_pass_val As String = "" Public Shared Property Pass_val() As Char Get Return var_pass_val End Get Set(ByVal value As String) var_pass_val = value End Set End Property End Class

Now at the time of assigning a value:<br />cls_pass_val.Pass_val='A'

and at the time of retrieving the value:

Dim var_c as Char var_c=cls_pass_val.Pass_val

Recommend

  • Restful WebService without annotations in eclipse using java
  • document.querySelector with dynamically created content [duplicate]
  • How to easily inspect styled-components using dev tools?
  • View current opened netNamedPipe channels?
  • What's the syntax to inherit documentation from another indexer?
  • Why the SequenceFile is truncated?
  • quiver not drawing arrows just lots of blue, matlab
  • AppleScript : find open tab in safari by name and open it
  • How do I display a dialog that asks the user multi-choice questıon using tkInter?
  • DIV instruction jumping to random location?
  • Ajax Upload File: $_FILES is empty but files exists in request header
  • Parsing a CSV string while ignoring commas inside the individual columns
  • Swing - Get new component under mouseReleased
  • MVC3 Razor - ListBox pre-select not working
  • Set the selected item in dropdownlist in MVC3
  • Alert pop up with LWUIT
  • Ajax Loaded meta Tags
  • ilmerge with a PFX file
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • Spring Data JPA custom method causing PropertyReferenceException
  • Can I display google adwords (AdView) in javafx on android
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Validaiting emails with Net.Mail MailAddress
  • sending/ receiving email in Java
  • Weird JavaScript statement, what does it mean?
  • How do you troubleshoot character encoding problems?
  • How to format a variable of double type
  • Cannot Parse HTML Data Using Android / JSOUP
  • File upload with ng-file-upload throwing error
  • AngularJs get employee from factory
  • Free memory of cv::Mat loaded using FileStorage API
  • Hits per day in Google Big Query
  • JTable with a ScrollPane misbehaving
  • how does django model after text[] in postgresql [duplicate]
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Java static initializers and reflection
  • unknown Exception android
  • How to Embed XSL into XML
  • failed to connect to specific WiFi in android programmatically
  • How can I use threading to 'tick' a timer to be accessed by other threads?