locked
Need help to send data from one screen to an other. RRS feed

  • Question

  • I would like to know if there is a way to send information from one Screen to a textbox that i will create at another screen. I need to create a market, where u choose the products u like and then by clicking at a "Checkout" button it will take you to an other page where u can see the final cost..

    THX for the help.

    Tuesday, January 10, 2012 2:24 PM

All replies

  • What environment are you working in: WPF, Silverlight, or Windows Phone?
    Tuesday, January 10, 2012 2:59 PM
  • i work in WPF
    Tuesday, January 10, 2012 3:37 PM
  • I would probably make both screens use the same ViewModel object (assuming you're using MVVM design). That way one screen can write to the data and one screen can read from the data by using data bindings. I find things are much simpler in the long run!
    • Proposed as answer by Brian Hilstrom Wednesday, January 11, 2012 2:10 PM
    Tuesday, January 10, 2012 4:33 PM
  • thx for the answer! as i am new to this it's a bit hard to figure out what to do.. i haven't created a Viewmodel..so  is there an other way to transfer the data that i get in one textbox to an other one?
    Friday, January 13, 2012 10:30 PM
  • Blend actually makes this really easy.  I'm going to show you pictures because, well I'm just not that good at explaining stuff. :)

    I created a project with 2 screens.

    The first screen had a textbox and a button.  (Fill your text in the textBox and click the button to navigate to screen2).

    The second screen I just put a textBlock.

    On the first screen I selected my textBox from the Objects and Timeline panel.  Then selected the "SetDataStoreValueAction" from the asset panel.  (Double-Click to apply it to the text box.)  This will create a DataStore for you that you can easily bind to from other screens.

     

    I bound the Value property to my text1.Text.  (Simply click the little box to the right, select element property binding, target the textBox and select text.)

    Then I opened up screen2 and bound that textBlock.Text to the DataStore > myText(string).  (Clicked the little box next to the TextBlock Text in the "Common Properties" panel.  Selected "Binding" from the drop down.  Then selected the DataStore property.)

    See... all that looks complicated with the way I explained it.  But I promise once you try it, you'll find it incredibly easy.

    ~Christine


    xaml Screen1...

    <UserControl
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" xmlns:pi="http://schemas.microsoft.com/prototyping/2010/interactivity" x:Name="Screen_1_Name"
    	mc:Ignorable="d"
    	x:Class="WpfPrototype2Screens.Screen_1"
    	Width="1000" Height="700">
    	<UserControl.Resources>
    		<ResourceDictionary>
    			<ResourceDictionary.MergedDictionaries>
    				<ResourceDictionary Source="ProjectDataSources.xaml"/>
    			</ResourceDictionary.MergedDictionaries>
    		</ResourceDictionary>
    	</UserControl.Resources>
    
    	<Grid x:Name="LayoutRoot" Background="White">
    		<TextBox x:Name="text1" HorizontalAlignment="Left" Style="{DynamicResource BasicTextBox-Sketch}" TextWrapping="Wrap" Text="My Text Here" VerticalAlignment="Top" Height="30.463" Width="259.327" Margin="8,8,0,0">
    			<i:Interaction.Triggers>
    				<i:EventTrigger EventName="TextChanged">
    					<ei:SetDataStoreValueAction PropertyName="myText" TargetObject="{Binding Mode=OneWay, Source={StaticResource DataStore}}" Value="{Binding Text, ElementName=text1}"/>
    				</i:EventTrigger>
    			</i:Interaction.Triggers>
    		</TextBox>
    		<Button Content="Button" HorizontalAlignment="Left" Style="{DynamicResource Button-Sketch}" VerticalAlignment="Top" Width="259.327" Margin="8,42.463,0,0">
    			<i:Interaction.Triggers>
    				<i:EventTrigger EventName="Click">
    					<pi:NavigateToScreenAction TargetScreen="WpfPrototype2Screens.Screen_2"/>
    				</i:EventTrigger>
    			</i:Interaction.Triggers>
    		</Button>
    	</Grid>
    </UserControl>

     

     

    xaml Screen2...

    <UserControl
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Name="Screen_2_Name"
    	mc:Ignorable="d"
    	x:Class="WpfPrototype2Screens.Screen_2"
    	Width="1000" Height="700">
    	<UserControl.Resources>
    		<ResourceDictionary>
    			<ResourceDictionary.MergedDictionaries>
    				<ResourceDictionary Source="ProjectDataSources.xaml"/>
    			</ResourceDictionary.MergedDictionaries>
    		</ResourceDictionary>
    	</UserControl.Resources>
    
    	<Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource DataStore}}">
    		<TextBlock x:Name="text2" HorizontalAlignment="Left" Style="{DynamicResource BasicTextBlock-Sketch}" Text="{Binding myText}" VerticalAlignment="Top" Margin="8,8,0,0" Width="294.483"/>
    	</Grid>
    </UserControl>




    Saturday, January 14, 2012 12:44 AM
  • Thank for the answer.. Now i also want to pass the data that appear in a textbox after i press a button.. I have created a calculator and i want the final sum to go to an other page. The method u suggested didn't work for this, is there any way?

     

    Saturday, January 14, 2012 1:39 PM
  • Where are you storing that calculation from the calculator?  In a database?  If so you don't need that method at all.  You just reconnect to your db on screen 2. 

     

    If you are displaying your calculation in a visible or hidden textblock on screen 2, it could very easily work.

     

    These might help you in creating a data source:

    http://expression.microsoft.com/en-us/library/cc294789

    http://expression.microsoft.com/en-us/library/cc295239

     

    ~Christine

     

    Edit:  I have uploaded a sample project HERE that will show you how to calculate and pass info back and forth between screens.  Including calculations.


    Saturday, January 14, 2012 5:36 PM