locked
Updating textBlock from another Binding textblock RRS feed

  • Question

  • Hello,

    I am trying to get data from binding TextBlock to be placed into another textblock. TextBlock named PriceBox information is pulled in by Json, and I want to have that information copied into MainPriceBox TextBlock. I might just be doing it incorrectly, but here is a copy of the to TextBlocks from my XAML.

    Thanks for the help

    John

    <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Price: " FontSize="20"/>
                                <TextBlock Name="PriceBox" Text="{Binding Value}" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="20" Width="229" RenderTransformOrigin="0.5,0.5"/>
                            </StackPanel>
                           
    
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
    
    <TextBox   x:Name="MainPricebox" Text="{Binding ElementName=IboxGoldPirces,Path=TextBox.DataContext}" HorizontalAlignment="Left" Margin="546,444,0,0" Grid.Row="1" TextWrapping="Wrap"  VerticalAlignment="Top" Width="175" IsReadOnly="True"/>


    John Lisenby developer of My PC Playbook

    Tuesday, October 22, 2013 3:13 AM

Answers

  • <TextBox x:Name="MainPricebox"

    Text="{Binding ElementName=IboxGoldPirces, Path=SelectedItem.Value}"

    HorizontalAlignment="Left"

    Margin="546,444,0,0" Grid.Row="1"

    TextWrapping="Wrap"

     VerticalAlignment="Top"

    Width="175"

    IsReadOnly="True"/>





    Tuesday, October 22, 2013 1:45 PM

All replies

  • Hello john,

    try to use listbox selectionchanged event. In this event try to get that selected value & show in textbox.

    Like this:

    //listbox selection event, listbox name is lstbox1
    var a = lstbox1.selectedItem;
    mainpricebox.text = a;

    Tuesday, October 22, 2013 4:05 AM
  • Hi Khant,

    Thanks for the reply. I used the above code and getting error: "Error 1 Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?) " . Am I missing something?

    Again thanks for the help,

    John


    John Lisenby developer of My PC Playbook

    Tuesday, October 22, 2013 12:52 PM
  • Try this -

    <TextBox   x:Name="MainPricebox" Text="{Binding ElementName=PriceBox,Path=Text}" HorizontalAlignment="Left" Margin="546,444,0,0" Grid.Row="1" TextWrapping="Wrap"  VerticalAlignment="Top" Width="175" IsReadOnly="True"/>

    Missed it was part of ListBox datatemplate, above solution won't work. 


    Thanks, Sachin



    • Edited by Sachin S Tuesday, October 22, 2013 2:14 PM
    Tuesday, October 22, 2013 1:03 PM
  • Hi Sachin,

    I also tried the above code, and the textblock did not update. Here is a link to my source code: https://dl.dropboxusercontent.com/u/42533148/What%20is%20it%20going%20for.zip

    Thanks,

    John


    John Lisenby developer of My PC Playbook

    Tuesday, October 22, 2013 1:21 PM
  • <TextBox x:Name="MainPricebox"

    Text="{Binding ElementName=IboxGoldPirces, Path=SelectedItem.Value}"

    HorizontalAlignment="Left"

    Margin="546,444,0,0" Grid.Row="1"

    TextWrapping="Wrap"

     VerticalAlignment="Top"

    Width="175"

    IsReadOnly="True"/>





    Tuesday, October 22, 2013 1:45 PM
  • Thanks everyone for the help! It's working.

    Thanks again,

    John


    John Lisenby developer of My PC Playbook

    Tuesday, October 22, 2013 2:10 PM