.NET Framework - WPF - come passare variabili fra Window?
Asked By ing. ignazio pinto
03-Nov-09 07:30 AM
Salve a tutti,
Ho il seguente problema:
Ho due form (in WPF due Window) che chiamo rispettivamente Form1 e Form2.
Nel Form1 ho una textbox che chiamo Textbox_1.
Entrambe i form sono aperti.
Faccio un operazione sul Form2 e ricavo un valore, ad esempio una stringa
che voglio passare alla textbox sul Form1.
In Windows Form bastava richiamare dal Form2 il Form1 e mi venivano esposti
tutti i controlli in esso contenuti,
quindi per accedere alla propriet? Text della textbox mi bastava utilizzare
il codice seguente nel Form2:
My.Forms.Form1.Textbox_1.Text= "stringa"
In WPF invece non mi vengono esposti i controlli contenuti nel Form1, ma
solo le propriet? della Window.
Come posso fare per ottenere lo stesso risultato?
Spero di essere stato abbastanza chiaro.
Grazie
Ignazio Pinto
System.Windows.RoutedEventArgs
(1)
RoutedEventArgs
(1)
UGIdotNET
(1)
TextBox
(1)
WPF
(1)
VB
(1)
Window1.Textbox
(1)
Form1.Textbox
(1)
Corrado Cavalli [MVP] replied to ing. ignazio pinto
ing. ignazio pinto submitted this idea :
x:Name="btnOk" />
--
Corrado Cavalli [Microsoft .NET MVP-MCP]
UGIdotNET - http://www.ugidotnet.org
Weblog: http://blogs.ugidotnet.org/corrado/
ing. ignazio pinto replied to Corrado Cavalli [MVP]

Scusa ma non ho capito.
Ho provato a settare il mio textbox con la propriet? FieldModifier nel
seguente modo sul Form1:
Ma se vado nel Form2, dal lato codice Vb e scrivo:
Form1.Textbox_1.Text
non funziona poich? il textbox continuo a non vederlo.
Per spiegarmi meglio, ho un form wpf che ? il seguente, nel quale compare
solo una textbox:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
ed un secondo form WPF nel quale c'? un pulsante
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="300" Width="300">
voglio fare in modo che premendo il pulsante si valorizzi la textbox su
Window1, quindi
nel code behind di quest'ultimo scrivo:
Partial Public Class Window2
Private Sub btnOk_Click(ByVal sender As Object, ByVal e As
System.Windows.RoutedEventArgs) Handles btnOk.Click
'qui vorrei valorizzare il textbox_1 in win form avrei scritto:
Window1.Textbox_1.Text="Pippo" ma in WPF anche con l'attributo
'x:FieldModifier="public" da qui non vedo il TextBox_1 appartenente
a Window1
End Sub
End Class
Grazie
Corrado Cavalli [MVP] replied to ing. ignazio pinto
ing. ignazio pinto formulated the question :
Ignazio,
Fortunatamente quell'orrore di default instance grazie al quale in VB ?
possibile scrivere cose tipo [NomeForm].NomePropriet?=x non ?
supportata in WPF, quindi se vuoi accede da Window2 agli elementi di
ing. ignazio pinto replied to Corrado Cavalli [MVP]
Grazie tante,
ho seguito il suggerimento e funziona benissimo...
file di Resource. Help Public Sub Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Help.Click MessageBox.Show("CIAO") End Sub Naturalmente Help mi da il seguente errore. la contiene." Grazie per gli eventuali suggerimenti VB.NET - Italian Discussions System.Windows RoutedEventArgs (1) CorradoN0SP4MPL34S3 (1) RoutedEventArgs (1) UGIdotNET (1) WPF (1) System.Object (1) Help.Click (1) Resource (1) Vipers expressed precisely : Non
variable to the C# code-behind from a XML event? Thanks. Expression Interactive Designer Discussions System.Windows.RoutedEventArgs (1) System.Windows.Controls (1) System.Windows.Input (1) System.Windows.Media (1) UGIdotNET (1) Button.WidthProperty (1) WPF (1) VB (1) I think you could: -Attach an event the successive click to determine previously clicked on HTH - - Corrado Cavalli [Microsoft .NET MVP-MCP] UGIdotNET - http: / / www.ugidotnet.org Weblog: http: / / blogs.ugidotnet.org / corrado / Sorry, Corrado, but all that was complete and totally way above my poor this point. End Sub Private Sub Window_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) If (previousButton IsNot Nothing) Then previousButton.BeginAnimation(Button.WidthProperty, da) End If previousButton
result As String = "OK" Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click result = "KO" End Sub Grazie per gli eventuali suggerimenti VB.NET - Italian Discussions System.ComponentModel.PropertyChangedEventArgs (1) System.Windows.RoutedEventArgs (1) PropertyChangedEventArgs (1) INotifyPropertyChanged (1) CorradoN0SP4MPL34S3 (1 RoutedEventArgs (1) UGIdotNET (1) System.ComponentModel (1) Vipers used his keyboard to write : Not so easy. . . XAML: xmlns
System.Windows.RoutedEventArgs error .NET Framework I am getting the following error when I ran my SIlverlight Usercontrol application. It is failing at the event handler below private void HandleGotFocus(object sender, RoutedEventArgs e) { var box = e.Source as TextBox; if (box ! = null) { box.Select(0, box.Text NV 89109" }; } if (address ! = null) this.DataContext = address; } Will appreciate any suggestions. ADO.NET Discussions System.Windows.RoutedEventArgs (1) System.Collections.Generic (1) System.Windows.Documents (1) System.Windows.Controls (1) System.Windows service provided. You can send feedback directly to my manager at: msdnmg@microsoft.com. keywords: System.Windows.RoutedEventArgs, error description: I am getting the following error when I ran my SIlverlight