Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp with using the visual tree in Silverlight
    primarykey
    data
    text
    <p>I have a question of how I can use the visual tree helper to get an object that I need. I have a user controll called DialogItemControll that I call from my main page like this: </p> <pre><code>DialogItemControll ivDialogWindow = new DialogItemControll() ivDialogWindow.ivSave.Click += new RoutedEventHandler(ivSave_Click); ivDialogWindow.Show(); </code></pre> <p>And then I have the method ivSave_Click that gets called when I click the save button on my user controll. That method looks like:</p> <pre><code> void ivSave_Click(object sender, RoutedEventArgs e) { var button = sender as Button; var firstStack = button.Parent as StackPanel; var secondStack = firstStack.Parent as StackPanel; TextBox te = secondStack.FindName("ivUserComment") as TextBox;} </code></pre> <p>This is where you can see my attempts to use the get parent and so on. Not so nicely done. So what I want is to get the whole object like:</p> <pre><code>var controll = ?? as DialogItemControll </code></pre> <p>My DialogItemControll looks like this :</p> <pre><code> &lt;C1:C1Window x:Class="DialogItemControll" 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:C1="clr-namespace:C1.Silverlight;assembly=C1.Silverlight" mc:Ignorable="d" d:DesignHeight="418" d:DesignWidth="401"&gt; &lt;Grid x:Name="LayoutRoot" Background="White"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="*" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;StackPanel Grid.Row="0" Margin="5,5,5,5"&gt; &lt;TextBlock Name="ivHelpComment" FontSize="18"&gt;test&lt;/TextBlock&gt; &lt;TextBox Name="ivUserComment" BorderThickness="2,2,2,2" Height="170"&gt;&lt;/TextBox&gt; &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Right" &gt; &lt;Button Name="ivSave" HorizontalAlignment="Right" Height="22" Width="70" Margin="0,10,20,0" Click="ivSave_Click"&gt;Spara&lt;/Button&gt; &lt;Button Name="ivCancel" HorizontalAlignment="Right" Height="22" Width="70" Margin="0,10,20,0" Click="ivCancel_Click"&gt;Avbryt&lt;/Button&gt; &lt;/StackPanel&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>C1 window is the same as user control, its just a third party control. Please help me with how I should use the tree helper in a good way to get the whole object.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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