title: How to Bind TextBlock Width when it is part of style
body: <p>I created my own class for AutoComplete and in its Style I made it in such away that if the text is nothing it shows a textblock. Everything works well except when text is nothing the TextBlock is smaller than the AutoComplete Element. I used Stretched="Fill" but this make the TextBlock stretched and the text inside of the textblock will stretched as well and look so ugly. I am thinking of binding the width of the textbloxk to the ActualWidth of the AutoComplete element but problem is that textblock is in the style and I cannot use the ElementName. Is there any way that Bind the width without using ElementName?</p>
  
  <p>Thank you so much</p>
  
  <pre><code>&lt;Window x:Class="Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Luna"
  xmlns:Microsoft_Windows_Themes2="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  
  Title="Window1" Height="300" Width="300" Background="Aqua"&gt;
  &lt;Window.Resources&gt;
      &lt;Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}"&gt;
          &lt;Setter Property="OverridesDefaultStyle" Value="true"/&gt;
          &lt;Setter Property="AllowDrop" Value="true"/&gt;
          &lt;Setter Property="MinWidth" Value="0"/&gt;
          &lt;Setter Property="MinHeight" Value="0"/&gt;
          &lt;Setter Property="FocusVisualStyle" Value="{x:Null}"/&gt;
          &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                  &lt;ControlTemplate TargetType="{x:Type TextBox}"&gt;
                      &lt;ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/&gt;
                  &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
      &lt;ControlTemplate x:Key="AutoCompleteComboBoxEditableTemplate" TargetType="{x:Type ComboBox}"&gt;
          &lt;Grid SnapsToDevicePixels="true"&gt;
              &lt;Border x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="1"&gt;
                  &lt;Grid Grid.IsSharedSizeScope="true"&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="1"/&gt;
                          &lt;ColumnDefinition Width="*"/&gt;
                          &lt;ColumnDefinition SharedSizeGroup="ComboBoxButton" Width="Auto"/&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;TextBox x:Name="PART_EditableTextBox" Margin="{TemplateBinding Padding}" Style="{StaticResource ComboBoxEditableTextBox}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Grid.Column="1" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"/&gt;
                  &lt;/Grid&gt;
              &lt;/Border&gt;
              &lt;Popup x:Name="PART_Popup" AllowsTransparency="true" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Focusable="false"&gt;
                  &lt;Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" Color="Transparent"&gt;
                      &lt;Border x:Name="DropDownBorder" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1"&gt;
                          &lt;ScrollViewer&gt;
                              &lt;ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Continue"/&gt;
                          &lt;/ScrollViewer&gt;
                      &lt;/Border&gt;
                  &lt;/Microsoft_Windows_Themes:SystemDropShadowChrome&gt;
              &lt;/Popup&gt;
          &lt;/Grid&gt;
          &lt;ControlTemplate.Triggers&gt;
              &lt;Trigger Property="HasItems" Value="false"&gt;
                  &lt;Setter Property="MinHeight" TargetName="DropDownBorder" Value="95"/&gt;
              &lt;/Trigger&gt;
              &lt;Trigger Property="IsEnabled" Value="false"&gt;
                  &lt;Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/&gt;
                  &lt;Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/&gt;
              &lt;/Trigger&gt;
              &lt;Trigger Property="IsGrouping" Value="true"&gt;
                  &lt;Setter Property="ScrollViewer.CanContentScroll" Value="false"/&gt;
              &lt;/Trigger&gt;
              &lt;Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true"&gt;
                  &lt;Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/&gt;
                  &lt;Setter Property="Color" TargetName="Shdw" Value="#71000000"/&gt;
              &lt;/Trigger&gt;
          &lt;/ControlTemplate.Triggers&gt;
      &lt;/ControlTemplate&gt;
  
      &lt;Style BasedOn="{StaticResource {x:Type ComboBox}}" TargetType="{x:Type ComboBox}"&gt;
          &lt;Setter Property="IsEditable" Value="true"&gt;&lt;/Setter&gt;
          &lt;Style.Triggers&gt;
              &lt;Trigger Property="IsEditable" Value="True"&gt;
                  &lt;Setter Property="IsTabStop" Value="false"/&gt;
                  &lt;Setter Property="Padding" Value="0,1"/&gt;
                  &lt;Setter Property="Template" Value="{StaticResource AutoCompleteComboBoxEditableTemplate}"/&gt;
              &lt;/Trigger&gt;
              &lt;MultiTrigger&gt;
                  &lt;MultiTrigger.Conditions&gt;
                      &lt;Condition Property="Text" Value="" /&gt;
                  &lt;/MultiTrigger.Conditions&gt;
                  &lt;Setter Property="Background"&gt;
                      &lt;Setter.Value&gt;
                          &lt;VisualBrush  Stretch="None"&gt;
                              &lt;VisualBrush.Visual&gt;
                                  &lt;TextBlock Text="Press F12" Margin="5,5,5,5" VerticalAlignment="Center" HorizontalAlignment="Left" 
                                         Foreground="Gray" Background="White" FontSize="16" Width="{Binding RelativeSource={RelativeSource Self}, Path=Width}"/&gt;
                              &lt;/VisualBrush.Visual&gt;
                          &lt;/VisualBrush&gt;
                      &lt;/Setter.Value&gt;
                  &lt;/Setter&gt;
              &lt;/MultiTrigger&gt;
              &lt;MultiTrigger&gt;
                  &lt;MultiTrigger.Conditions&gt;
                      &lt;Condition Property="SelectedItem" Value="{x:Null}"/&gt;
                      &lt;Condition Property="IsEnabled" Value="True"/&gt;
                  &lt;/MultiTrigger.Conditions&gt;
                  &lt;MultiTrigger.Setters&gt;
                      &lt;Setter Property="BorderBrush" Value="Red"/&gt;
                      &lt;Setter Property="BorderThickness" Value="1"/&gt;
                  &lt;/MultiTrigger.Setters&gt;
              &lt;/MultiTrigger&gt;
          &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
  
  &lt;/Window.Resources&gt;
  &lt;Grid&gt;
      &lt;ComboBox IsEditable="True" x:Name="TestCB" Width="100" Height="50" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>