Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass the value of datagrid’s cell of the selected row to a texblock in ChildWindow in Silverlight?
    text
    copied!<p>I generate datagrid content from the list. I need to be able to pass the value of the ‘Name’ cell of the selected row in the datagrid to a texblock of the child window. The child windows is launched by clicking the context menu item. The scenario is the the user right click the mouse over selected row “name’ cell, then pick the context menu item that launch the childwindow. ChildWindow is launched with the textblock text value from that cell from the datagrid. Any ideas are highly appreciated! Thank you in advance!</p> <p>Datagrid with context menu:</p> <pre><code>&lt;sdk:DataGrid x:Name="dgPack" ItemsSource="{Binding Source={StaticResource PackagesCollectionViewSource}}"&gt; &lt;InputToolkit:ContextMenuService.ContextMenu&gt; &lt;InputToolkit:ContextMenu x:Name="cmPackages_DataGrid" DataContext="{Binding Source={StaticResource GlobalLabelsDataSource}}"&gt; &lt;InputToolkit:MenuItem x:Name="item1" Header="item1"/&gt; &lt;InputToolkit:MenuItem x:Name="GetChildWindow" Header="GetChildWindow" Click="GetChildWindow_Click"/&gt; &lt;/InputToolkit:ContextMenu&gt; &lt;/InputToolkit:ContextMenuService.ContextMenu&gt; &lt;sdk:DataGrid.Columns&gt; &lt;sdk:DataGridTextColumn x:Name="DataGrid_Name" Binding="{Binding Name}" Header="Name" /&gt; &lt;sdk:DataGridTextColumn x:Name="DataGrid_Version" Binding="{Binding Version}" Header="Version" /&gt; &lt;sdk:DataGridTextColumn x:Name="DataGrid_Size" Binding="{Binding Size}" Header="Size" /&gt; &lt;/sdk:DataGrid.Columns&gt; </code></pre> <p></p> <p>Method in code behind to launch childwindow:</p> <pre><code>private void GetChildWindow_Click(object sender, System.Windows.RoutedEventArgs e) { var selectedItem = PackVM.SelectedPack; if (selectedItem != null) { var bpw = new GetChildWindow1_ChildWindow(selectedItem.Id); bpw.Show(); } } </code></pre> <p>List:</p> <pre><code>public List&lt;Pack&gt; GetCollection() { return new List&lt;Pack&gt;() { new Pack() { Name="item1", Size=10, Version="1"}, new Pack() { Name="item2", Size=12, Version="5", }, }; } </code></pre> <p>And finally child window:</p> <pre><code>&lt;Grid x:Name="LayoutRoot"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;/Grid.RowDefinitions &lt;Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" Margin="0,0,79,0" HorizontalAlignment="Right" Grid.Row="1" /&gt; &lt;Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Grid.Row="1" /&gt; &lt;TextBlock x:Name="Message" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top"/&gt; &lt;/Grid&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload