Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing TextBox in a DataTemplate
    primarykey
    data
    text
    <p>I have the XAML like this. (This code is just some part of my source code) </p> <pre><code>&lt;UserControl x:Class="EmployeeClass" ...............&gt; ............. ............. &lt;ListView x:Name="EmployeeList" Width="700" Height="500" Margin="10" ItemsSource ="{Binding Source={x:Static local:Company.employeeList}}" Background="Black" ItemTemplateSelector="{DynamicResource myDataTemplateSelector}" Focusable="False" IsSynchronizedWithCurrentItem="True"&gt; &lt;/ListView&gt; &lt;/UserControl&gt; </code></pre> <p>Here is one of my data template</p> <pre><code> &lt;DataTemplate x:Key="SeniorEmployee" DataType="{x:Type local:ListEmployee}"&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition/&gt; &lt;ColumnDefinition/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="10"&gt; &lt;Image x:Name="ProfilePicture" Source="{Binding Path=ProfilePict}" Stretch="Fill" Width="80" Height="80" VerticalAlignment="Top"&gt;&lt;/Image&gt; &lt;StackPanel Orientation="Vertical" Margin="5"&gt; &lt;TextBlock Text="{Binding Path=Attribution}" Foreground="White" TextWrapping="Wrap" Width="400" VerticalAlignment="Top" HorizontalAlignment="Left"/&gt; &lt;StackPanel Margin="7,5,0,7"&gt; &lt;UISkripsi3:CommandTextBox Name="AttributionTextBox" HorizontalAlignment="Left" Margin="10,5" Panel.ZIndex="1" BannerText="Add to the attribution" FontSize="{DynamicResource LargeFontSize1}" SpellCheck.IsEnabled="True" Style="{DynamicResource AttributionTextBoxStyle}" TextWrapping="Wrap"&gt; &lt;/UISkripsi3:CommandTextBox&gt; &lt;Button Style="{DynamicResource StandardButtonStyle}" IsEnabled="{Binding ElementName=AttributionTextBox, Path=Text, Converter={StaticResource IsStringNullOrWhitespaceConverter}, ConverterParameter=Inverse}" Click="AttributionButtonClick" Height="22" HorizontalAlignment="Right" Margin="10,4,10,0" Panel.ZIndex="0" CommandTarget="{Binding ElementName=AttributionTextBox}" Content="Show" FontSize="{DynamicResource LargeFontSize1}"&gt; &lt;/Button&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; </code></pre> <p>If user type something in the AttributionTextBox and click the button, there will be a messagebox showing text typed by the user. I have tried <a href="http://blogs.msdn.com/b/wpfsdk/archive/2007/04/16/how-do-i-programmatically-interact-with-template-generated-elements-part-ii.aspx" rel="nofollow noreferrer"><a href="http://blogs.msdn.com/b/wpfsdk/archive/2007/04/16/how-do-i-programmatically-interact-with-template-generated-elements-part-ii.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/b/wpfsdk/archive/2007/04/16/how-do-i-programmatically-interact-with-template-generated-elements-part-ii.aspx</a></a> and visual tree helper at h*tp://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper.aspx</p> <p>My problem is, I can't find the AttributionTextBox in code behind. I also can't access the EmployeeList Listview because it wasn't generated in the code behind. Can anyone help me to solve the problem?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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