title: Using FindName in Powershell a WPF
body: <p>I need some help with Powershell and WPF.</p>
  
  <p>I am modifying an Add-In that someone made using WPF and powershell. So I'm not 100% sure how the xaml structure is laid out. What I want to do is to modify the Text property of a certain element that is generated during runtime. I used Snoop2.8.0 and found the element that I want to modify, and it has a Name property "FreeTextBox". I intend to use the FindName method to get to the element, however, the FindName method returns nothing.</p>
  
  <p>I have read in a few posts that there is a separate thing called contentPresenter where these runtime elements are stored and that I need to reference it to get to my textbox, however, I don't know how to do this. I would appreciate if anyone could point me in the right direction.</p>
  
  <p>Regards
  Ilyas</p>
  
  <p>Edit:
  Code for the form</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;WPF:DSWindow 
  
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:WPF="clr-namespace:dataStandard.UI.View;assembly=dataStandard.UI" xmlns:system="clr-namespace:System;assembly=mscorlib" x:Name="InventorWindow" WindowStyle="ToolWindow" ShowInTaskbar="False" Topmost="True" SizeToContent="WidthAndHeight" Background="#F0F0F0" ResizeMode="NoResize"&gt;
    &lt;WPF:DSWindow.Resources&gt;
      &lt;Style x:Key="DynamicDataGridCellStyle" TargetType="{x:Type DataGridCell}"&gt;
        &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
            &lt;ControlTemplate&gt;
              &lt;ComboBox ItemsSource="{Binding ListValues}" Text="{WPF:ValidatedBinding Value}" IsEditable="True"&gt;&lt;/ComboBox&gt;
            &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
        &lt;/Setter&gt;
        &lt;Style.Triggers&gt;
          &lt;Trigger Property="IsSelected" Value="True"&gt;
            &lt;Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" /&gt;
            &lt;Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" /&gt;
            &lt;Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" /&gt;
          &lt;/Trigger&gt;
          &lt;Trigger Property="IsKeyboardFocusWithin" Value="True"&gt;
            &lt;Setter Property="BorderBrush" Value="{DynamicResource {x:Static DataGrid.FocusBorderBrushKey}}" /&gt;
          &lt;/Trigger&gt;
          &lt;DataTrigger Binding="{Binding ListValues.Count}" Value="0"&gt;
            &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                &lt;ControlTemplate&gt;
                  &lt;TextBox Text="{WPF:ValidatedBinding Value}"&gt;&lt;/TextBox&gt;
                &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
            &lt;/Setter&gt;
          &lt;/DataTrigger&gt;
          &lt;DataTrigger Binding="{Binding Typ}" Value="DateTime"&gt;
            &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                &lt;ControlTemplate&gt;
                  &lt;DatePicker SelectedDate="{WPF:ValidatedBinding Value, StringFormat='dd/MM/yyyy'}" /&gt;
                &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
            &lt;/Setter&gt;
          &lt;/DataTrigger&gt;
          &lt;DataTrigger Binding="{Binding Typ}" Value="Boolean"&gt;
            &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                &lt;ControlTemplate&gt;
                  &lt;ComboBox SelectedItem="{WPF:ValidatedBinding Value}"&gt;
                    &lt;system:Boolean&gt;True&lt;/system:Boolean&gt;
                    &lt;system:Boolean&gt;False&lt;/system:Boolean&gt;
                  &lt;/ComboBox&gt;
                &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
            &lt;/Setter&gt;
          &lt;/DataTrigger&gt;
        &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
      &lt;Style TargetType="{x:Type TextBox}"&gt;
        &lt;Setter Property="VerticalAlignment" Value="Center" /&gt;
        &lt;Style.Triggers&gt;
          &lt;Trigger Property="Validation.HasError" Value="true"&gt;
            &lt;Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}" /&gt;
          &lt;/Trigger&gt;
          &lt;DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsReadOnly}" Value="True"&gt;
            &lt;Setter Property="Background" Value="#F0F0F0"&gt;&lt;/Setter&gt;
          &lt;/DataTrigger&gt;
        &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
      &lt;Style TargetType="{x:Type ComboBox}"&gt;
        &lt;Style.Triggers&gt;
          &lt;Trigger Property="Validation.HasError" Value="true"&gt;
            &lt;Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}" /&gt;
          &lt;/Trigger&gt;
        &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
      &lt;Style TargetType="{x:Type DatePicker}"&gt;
        &lt;Style.Triggers&gt;
          &lt;Trigger Property="Validation.HasError" Value="true"&gt;
            &lt;Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}" /&gt;
          &lt;/Trigger&gt;
        &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
      &lt;Style x:Key="FileNameStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}"&gt;
        &lt;Style.Triggers&gt;
          &lt;MultiDataTrigger&gt;
            &lt;MultiDataTrigger.Conditions&gt;
              &lt;Condition Binding="{Binding CreateMode}" Value="True"&gt;&lt;/Condition&gt;
              &lt;Condition Binding="{Binding ElementName=NumSchms, Path=IsEnabled}" Value="True"&gt;&lt;/Condition&gt;
            &lt;/MultiDataTrigger.Conditions&gt;
            &lt;Setter Property="Text" Value="{Binding UIString[LBL59]}"&gt;&lt;/Setter&gt;
            &lt;Setter Property="IsReadOnly" Value="True"&gt;&lt;/Setter&gt;
          &lt;/MultiDataTrigger&gt;
          &lt;MultiDataTrigger&gt;
            &lt;MultiDataTrigger.Conditions&gt;
              &lt;Condition Binding="{Binding CreateMode}" Value="True"&gt;&lt;/Condition&gt;
              &lt;Condition Binding="{Binding ElementName=NumSchms, Path=IsEnabled}" Value="False"&gt;&lt;/Condition&gt;
            &lt;/MultiDataTrigger.Conditions&gt;
            &lt;Setter Property="Text" Value="{Binding Prop[DocNumber].Value}"&gt;&lt;/Setter&gt;
          &lt;/MultiDataTrigger&gt;
          &lt;DataTrigger Binding="{Binding EditMode}" Value="True"&gt;
            &lt;Setter Property="Background" Value="#F0F0F0" /&gt;
            &lt;Setter Property="IsReadOnly" Value="True"&gt;&lt;/Setter&gt;
            &lt;Setter Property="Text" Value="{Binding Prop[_FileName].Value}"&gt;&lt;/Setter&gt;
          &lt;/DataTrigger&gt;
        &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
      &lt;Style x:Key="NumSchmStyle" TargetType="{x:Type ComboBox}"&gt;
        &lt;Style.Triggers&gt;
          &lt;DataTrigger Binding="{Binding CreateMode}" Value="True"&gt;
            &lt;Setter Property="ItemsSource" Value="{Binding PsList[GetNumSchms]}"&gt;&lt;/Setter&gt;
            &lt;Setter Property="IsEnabled" Value="{Binding RelativeSource={RelativeSource Self}, Path=Items.Count}"&gt;&lt;/Setter&gt;
          &lt;/DataTrigger&gt;
          &lt;DataTrigger Binding="{Binding EditMode}" Value="True"&gt;
            &lt;Setter Property="Text" Value="{Binding UIString[LBL27]}"&gt;&lt;/Setter&gt;
            &lt;Setter Property="Background" Value="#F0F0F0" /&gt;
            &lt;Setter Property="IsEditable" Value="True"&gt;&lt;/Setter&gt;
            &lt;Setter Property="IsReadOnly" Value="True"&gt;&lt;/Setter&gt;
          &lt;/DataTrigger&gt;
        &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
      &lt;Style TargetType="{x:Type Label}"&gt;
        &lt;Style.Triggers&gt;
          &lt;DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Content}" Value="{x:Null}"&gt;
            &lt;Setter Property="BorderThickness" Value="1"&gt;&lt;/Setter&gt;
            &lt;Setter Property="BorderBrush" Value="#ff0000"&gt;&lt;/Setter&gt;
          &lt;/DataTrigger&gt;
        &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
  
      &lt;BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /&gt;
      &lt;XmlDataProvider x:Key="ComboDataSource" Source="C:\CHM Vault\Libraries\data.xml"&gt;&lt;/XmlDataProvider&gt;
      &lt;XmlDataProvider x:Key="JobCodeDataSource" Source="C:\CHM Vault\Libraries\jobcode.xml"&gt;&lt;/XmlDataProvider&gt;
    &lt;/WPF:DSWindow.Resources&gt;
    &lt;Window.Style&gt;
      &lt;Style TargetType="{x:Type WPF:DSWindow}"&gt;
        &lt;Style.Triggers&gt;
          &lt;MultiDataTrigger&gt;
            &lt;MultiDataTrigger.Conditions&gt;
              &lt;Condition Binding="{Binding CreateMode}" Value="True"&gt;&lt;/Condition&gt;
              &lt;Condition Binding="{Binding CopyMode}" Value="True"&gt;&lt;/Condition&gt;
            &lt;/MultiDataTrigger.Conditions&gt;
            &lt;Setter Property="Title"&gt;
              &lt;Setter.Value&gt;
                &lt;MultiBinding StringFormat="{}{0} - '{1}'"&gt;
                  &lt;Binding Path="UIString[LBL60]" /&gt;
                  &lt;Binding Path="PathAndFileNameHandler.OriginalFileName" /&gt;
                &lt;/MultiBinding&gt;
              &lt;/Setter.Value&gt;
            &lt;/Setter&gt;
          &lt;/MultiDataTrigger&gt;
          &lt;MultiDataTrigger&gt;
            &lt;MultiDataTrigger.Conditions&gt;
              &lt;Condition Binding="{Binding CreateMode}" Value="True"&gt;&lt;/Condition&gt;
              &lt;Condition Binding="{Binding CopyMode}" Value="False"&gt;&lt;/Condition&gt;
            &lt;/MultiDataTrigger.Conditions&gt;
            &lt;Setter Property="Title"&gt;
              &lt;Setter.Value&gt;
                &lt;MultiBinding StringFormat="{}{0} - '{1}'"&gt;
                  &lt;Binding Path="UIString[LBL24]" /&gt;
                  &lt;Binding Path="PathAndFileNameHandler.OriginalFileName" /&gt;
                &lt;/MultiBinding&gt;
              &lt;/Setter.Value&gt;
            &lt;/Setter&gt;
          &lt;/MultiDataTrigger&gt;
          &lt;DataTrigger Binding="{Binding CreateMode}" Value="False"&gt;
            &lt;Setter Property="Title"&gt;
              &lt;Setter.Value&gt;
                &lt;MultiBinding StringFormat="{}{0} - '{1}'"&gt;
                  &lt;Binding Path="UIString[LBL25]" /&gt;
                  &lt;Binding Path="PathAndFileNameHandler.FileName" /&gt;
                &lt;/MultiBinding&gt;
              &lt;/Setter.Value&gt;
            &lt;/Setter&gt;
          &lt;/DataTrigger&gt;
        &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
    &lt;/Window.Style&gt;
    &lt;DockPanel HorizontalAlignment="Left" Height="Auto" Margin="20" VerticalAlignment="Top" Width="Auto"&gt;
      &lt;Grid Margin="0,10,0,0" DockPanel.Dock="Bottom" VerticalAlignment="Bottom"&gt;
        &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="140" /&gt;
          &lt;ColumnDefinition Width="*" /&gt;
          &lt;ColumnDefinition Width="80" /&gt;
          &lt;ColumnDefinition Width="20" /&gt;
          &lt;ColumnDefinition Width="80" /&gt;
        &lt;/Grid.ColumnDefinitions&gt;
        &lt;Border Grid.Column="0" BorderBrush="White" BorderThickness="5" VerticalAlignment="Bottom" HorizontalAlignment="Center" Visibility="{Binding CopyMode, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="5,0,5,22"&gt;
          &lt;Image VerticalAlignment="Center" Width="120" Height="120" Source="{Binding Prop[Thumbnail].Value}" /&gt;
        &lt;/Border&gt;
        &lt;Button Command="{Binding CloseWindowCommand, ElementName=InventorWindow}" IsEnabled="True" Grid.Column="2" Margin="0,5,0,5" Width="80" HorizontalAlignment="Right" VerticalAlignment="Center" ToolTipService.ShowOnDisabled="True" ToolTip="{Binding UIString[LBL35], FallbackValue=Cancel}" Content="{Binding UIString[BTN1], FallbackValue=OK}" /&gt;
        &lt;Button Grid.Column="4" Width="80" HorizontalAlignment="Right" Margin="0,5,0,5" VerticalAlignment="Center" Command="{Binding CancelWindowCommand, ElementName=InventorWindow}" IsCancel="true" Content="{Binding UIString[BTN2], FallbackValue=Cancel}" /&gt;
      &lt;/Grid&gt;
      &lt;Grid Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" DockPanel.Dock="Left"&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="auto" /&gt;
          &lt;RowDefinition Height="auto" /&gt;
          &lt;RowDefinition Height="auto" /&gt;
      &lt;/Grid.RowDefinitions&gt;
  
          &lt;Grid Name="GeneralFileProp" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="0"&gt;
            &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="8" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="8" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="8" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="8" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="8" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
            &lt;/Grid.RowDefinitions&gt;
            &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="140" /&gt;
              &lt;ColumnDefinition Width="350" /&gt;
            &lt;/Grid.ColumnDefinitions&gt;
            &lt;Label Grid.Row="0" Grid.Column="0" Content="{Binding UIString[LBL10], FallbackValue=Number Scheme}" /&gt;
            &lt;ComboBox Grid.Column="1" Grid.Row="0" x:Name="NumSchms" DisplayMemberPath="Name" SelectedIndex="0" Style="{StaticResource NumSchmStyle}" /&gt;
            &lt;Label Grid.Row="2" Grid.Column="0" Content="{Binding UIString[LBL31], FallbackValue=Number}" /&gt;
            &lt;WPF:DSNumSchemeCtrl Grid.Row="2" Grid.Column="1" Scheme="{Binding SelectedItem, ElementName=NumSchms}" IsEnabled="{Binding IsEnabled, ElementName=NumSchms}" GeneratedNumberProperty="DocNumber" /&gt;
            &lt;Label Content="Folder" Grid.Row="4" Grid.Column="0" Visibility="{Binding CreateMode, Converter={StaticResource BooleanToVisibilityConverter}}" /&gt;
            &lt;WrapPanel Name="BreadCrumb" Grid.Column="1" Grid.Row="4" ItemWidth="165"&gt;
              &lt;WrapPanel.Resources&gt;
                &lt;Style TargetType="{x:Type ComboBox}"&gt;
                  &lt;Setter Property="Margin" Value="0,5,15,0" /&gt;
                  &lt;Setter Property="ToolTip" Value="{Binding Path=SelectedValue.Name, RelativeSource={RelativeSource Self}}" /&gt;
                &lt;/Style&gt;
              &lt;/WrapPanel.Resources&gt;
            &lt;/WrapPanel&gt;
            &lt;Label Content="Description" Grid.Column="0" Grid.Row="6" /&gt;
            &lt;TextBox Text="{Binding Prop[Description].Value}" Grid.Column="1" Grid.Row="6" x:Name="Description" VerticalScrollBarVisibility="Auto" Height="50" TextWrapping="Wrap" AcceptsReturn="True" /&gt;
            &lt;Label Content="Path" Grid.Column="0" Grid.Row="8" /&gt;
            &lt;TextBox Text="{Binding PathAndFileNameHandler.Path}" Grid.Column="1" Grid.Row="8" IsReadOnly="True" Background="#F0F0F0" /&gt;
            &lt;Label Content="File Name" Grid.Row="10" Grid.Column="0" /&gt;
            &lt;TextBox Grid.Row="10" Grid.Column="1" x:Name="FILENAME" Style="{StaticResource FileNameStyle}" /&gt;
          &lt;/Grid&gt;
  
          &lt;Grid Name="ModelProp" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1"&gt;
            &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="8" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="8" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="8" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="8" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="8" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
            &lt;/Grid.RowDefinitions&gt;
            &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="140" /&gt;
              &lt;ColumnDefinition Width="350" /&gt;
            &lt;/Grid.ColumnDefinitions&gt;
            &lt;Label Content="Category" Grid.Row="0" Grid.Column="0" /&gt;
            &lt;ComboBox x:Name="ItemCategory" Grid.Row="0" Grid.Column="1" ItemsSource="{Binding Source={StaticResource ComboDataSource}, XPath=/Data/ItemCat/*}" DisplayMemberPath="@Name" SelectedValue="{Binding Prop[Item Category].Value}" SelectedValuePath="@Name" IsEnabled="{Binding CreateMode}" /&gt;    
            &lt;!-- &lt;ComboBox x:Name="Categories" DisplayMemberPath="Name" SelectedItem="{Binding DynamicPropertiesCategory}" ItemsSource="{Binding PsList[GetCategories]}" SelectedIndex="0" Grid.Row="0" Grid.Column="1" IsEnabled="{Binding CreateMode}" /&gt; --&gt;
            &lt;Label Content="Model" Grid.Row="2" Grid.Column="0" /&gt;
            &lt;ComboBox x:Name="Model" Grid.Column="1" Grid.Row="2" ItemsSource="{Binding Source={StaticResource ComboDataSource}, XPath=/Data/ModelStd/*}" DisplayMemberPath="@Name" Text="{Binding Prop[Model].Value}" SelectedValue="{Binding Prop[Model].Value}" SelectedValuePath="@Name" IsEditable="True" /&gt;
            &lt;Label Content="Order Code" Grid.Row="4" Grid.Column="0" /&gt;
            &lt;TextBox Text="{Binding Prop[Order Code].Value}" Grid.Row="4" Grid.Column="1" /&gt;
            &lt;Label Content="Rating" Grid.Row="6" Grid.Column="0" /&gt;
            &lt;TextBox Text="{Binding Prop[Rating].Value}" Grid.Row="6" Grid.Column="1" /&gt;      
            &lt;Label Content="Brand" Grid.Row="8" Grid.Column="0" /&gt;
            &lt;TextBox Text="{Binding Prop[Brand].Value}" Grid.Row="8" Grid.Column="1" /&gt;      
            &lt;Label Content="Manufacturing Length" Grid.Row="10" Grid.Column="0" /&gt;
            &lt;TextBox Text="{Binding Prop[Manufacturing Length].Value}" Grid.Row="10" Grid.Column="1" /&gt;   
          &lt;/Grid&gt;
  
          &lt;Grid Name="DrawingProp" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="2"&gt;
            &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="8" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="8" /&gt;
              &lt;RowDefinition Height="auto" /&gt;
              &lt;RowDefinition Height="8" /&gt;
              &lt;RowDefinition Height="auto" /&gt;   
            &lt;/Grid.RowDefinitions&gt;
            &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="140" /&gt;
              &lt;ColumnDefinition Width="350" /&gt;
            &lt;/Grid.ColumnDefinitions&gt;
            &lt;Label Content="Job Code" Grid.Row="0" Grid.Column="0" /&gt;
            &lt;ComboBox x:Name="JobCode" Grid.Column="1" Grid.Row="0" ItemsSource="{Binding Source={StaticResource JobCodeDataSource}, XPath=/JobCode/*}" DisplayMemberPath="@Code"  SelectedValue="{Binding Prop[Job Code].Value}" SelectedValuePath="@Code" IsEnabled="True"/&gt;
            &lt;Label Content="Client" Grid.Row="2" Grid.Column="0" /&gt;
            &lt;TextBox Name="Client" Text="{Binding Prop[Client].Value}" Grid.Row="2" Grid.Column="1" IsEnabled="False" /&gt;  
            &lt;Label Content="Project Title" Grid.Row="4" Grid.Column="0" /&gt;
            &lt;TextBox Name="ProjectTitle" Text="{Binding Prop[Project Title].Value}" Grid.Row="4" Grid.Column="1" IsEnabled="False"/&gt;      
            &lt;TextBox Name="Treatment" Text="{Binding Prop[Treatment].Value}" Grid.Row="6" Grid.Column="1" IsEnabled="True"/&gt;      
  
          &lt;/Grid&gt;
  
      &lt;/Grid&gt;
    &lt;/DockPanel&gt;
  &lt;/WPF:DSWindow&gt;
  </code></pre>
  
  <p>Code for the behavior</p>
  
  <pre><code>function InitializeWindow
  {
      $dsWindow.Width = 500
      $dsWindow.Height = 400
  
      $Prop["Job Code"].add_PropertyChanged({p
  
        param( $parameter)
  
        StateChanged
  
        })
  
      If (($Prop["_FileExt"].Value -eq "IDW") -or ($Prop["_FileExt"].Value -eq "DWG"))
      {      
        $dsWindow.FindName("ModelProp").Visibility="Collapsed"
        $dsWindow.FindName("DrawingProp").Visibility="Visible"
      }
      Else
      {
        $dsWindow.FindName("ModelProp").Visibility="Visible"
        $dsWindow.FindName("DrawingProp").Visibility="Collapsed"
      }
  
  
  
      $mWindowName = $dsWindow.Name
      switch($mWindowName)
      {
          "InventorWindow"
          {   
              #rules applying for Inventor            
          }
          "AutoCADWindow"
          {
              #rules applying for AutoCAD
          }
          default
          {
              #rules applying commonly
          }
      }
      if ($Prop["_CreateMode"].Value)
      {
          $mappedRootPath = $Prop["_VaultVirtualPath"].Value + $Prop["_WorkspacePath"].Value
          $mappedRootPath = $mappedRootPath -replace "\\", "/" -replace "//", "/"
          if ($mappedRootPath -eq '')
          {
              $mappedRootPath = '$'
          }
          $rootFolder = $vault.DocumentService.GetFolderByPath($mappedRootPath)
          $root = New-Object PSObject -Property @{ Name = $rootFolder.Name; ID=$rootFolder.Id }   
          AddCombo -data $root
      }
  
  }
  function AddinLoaded
  {
      #Executed when DataStandard is loaded in Inventor
  }
  function AddinUnloaded
  {
      #Executed when DataStandard is unloaded in Inventor
  }
  
  function GetNumSchms
  {
      try
      {
          $numSchems = $vault.DocumentService.GetNumberingSchemesByType('Activated')
          if ($numSchems.Count -gt 0) 
          {
              $list = New-Object 'System.Collections.Generic.List[System.Object]'
              foreach ($item in $numSchems) 
              {
                  if ($item.IsDflt)
                  {
                      $list.Insert(0,$item)
                  }
                  else
                  {
                      $list.Add($item)
                  }
              }
              return $list
          }
      }
      catch [System.Exception]
      {       
          #[System.Windows.MessageBox]::Show($error)
      }   
  }
  
  function GetCategories
  {
      if ($Prop["_CreateMode"].Value)
      {
          $cats = $vault.CategoryService.GetCategoriesByEntityClassId("FILE", $true)
          if ($cats.Count -gt 0)
          {
              $list = New-Object 'System.Collections.Generic.List[System.Object]'
              foreach ($item in $cats) 
              {
                  $list.Add($item)
              }
              return $list
          }        
      }
      if ($Prop["_EditMode"].Value)
      {
          return GetCategoryByFileName $Prop["_FileName"].Value
      }
  }
  
  
  function OnPostCloseDialog
  {
      $mWindowName = $dsWindow.Name
      switch($mWindowName)
      {
          "InventorWindow"
          {
              #rules applying for Inventor
              If (($Prop["_FileExt"].Value -eq "IDW") -or ($Prop["_FileExt"].Value -eq "DWG"))
              {
                  If ($Prop["DocNumber"].Value.substring(0,1) -eq "Q")
                  {
                      $Prop["DocNumber"].Value=$Prop["DocNumber"].Value.substring($Prop["DocNumber"].Value.length-5,5)
                  }
              }
          }
          "AutoCADWindow"
          {
              #rules applying for AutoCAD
          }
          default
          {
              #rules applying commonly
          }
      }
  }
  
  function GetCategoryByFileName($fileName)
  {
      $filePropDefs = $vault.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE");
      $fileNamePropDef = $filePropDefs | Where-Object {$_.SysName -eq "ClientFileName"}
      $searchCond = New-Object -type Autodesk.Connectivity.WebServices.SrchCond
      $searchCond.PropDefId = $fileNamePropDef.Id
      $searchCond.PropTyp = [Autodesk.Connectivity.WebServices.PropertySearchType]::SingleProperty
      $searchCond.SrchTxt = $fileName
      $searchCond.SrchOper = 3
      $searchCond.SrchRule = [Autodesk.Connectivity.WebServices.SearchRuleType]::Must
      $bookmark = ""
      $status = $null
      $cat = $null
      $findFilesBySearchConditions = $vault.DocumentService.FindFilesBySearchConditions($searchCond, $null, $null, $false, $true, [ref]$bookmark, [ref]$status)
      if ($findFilesBySearchConditions -ne $null)
      {
          $cat = New-Object Autodesk.Connectivity.WebServices.Cat 
          $cat.Id = $findFilesBySearchConditions[0].Cat.CatId
          $cat.Name = $findFilesBySearchConditions[0].Cat.CatName
      }
      return $cat;
  }
  
  function StateChanged
  {
  $jobdata="C:\ProgramData\Autodesk\Vault 2016\Extensions\DataStandard\CAD\Configuration\jobcode.xml"
  $jobcodes = [xml](Get-Content $jobdata)
  $job=$jobcodes.JobCode.Job|where {$_.Code -eq $Prop["Job Code"].Value} 
  $Prop["Project Title"].Value=$job.Title
  $Prop["Client"].Value=$job.Client
  #[System.Windows.Forms.MessageBox]::Show($dswindow.FindName("FreeTextBox").Text) 
  #$dsWindow.FindName("FreeTextBox").Text=$Prop["Job Code"].Value
  }
  </code></pre>
  
  <p>As can be seen in the last line of this second code, I am trying to get use findname to get the FreeTextBox that was created from the main application. Unfortunately I don't have the code that creates the textbox as this is an addin that calls from the main application. I used snoop to find out the properties of the element itself, but stack doesn't allow me to post images yet.</p>