Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try using DataContext property, for example like this:</p> <pre><code>&lt;Style TargetType="{x:Type local:EntityTabItem}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type local:EntityTabItem}"&gt; &lt;Border&gt; &lt;Grid&gt; &lt;Border x:Name="borderTop" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"/&gt; &lt;StackPanel Orientation="Horizontal" Margin="0,0,2,0"&gt; &lt;!-- Want to bind the FileName to this TextBlock --&gt; &lt;TextBlock VerticalAlignment="Center" Text="{Binding Path=FileName}" Margin="-1,0,0,0" Padding="6,1,10,1"/&gt; &lt;Button x:Name="closeButton" VerticalAlignment="Center" Content="X" Style="{StaticResource TabCloseButton}"/&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="ContentTemplate"&gt; &lt;Setter.Value&gt; &lt;DataTemplate&gt; &lt;Grid Background="White"&gt; &lt;!-- Want to bind the FileText to this TextBox --&gt; &lt;TextBox Margin="15,0,0,0" BorderBrush="{x:Null}" Text="{Binding Path=FileText}"/&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; public class EntityTabItem : TabItem { private Entity _myEntity; public Entity MyEntity { get { return _myEntity; } set { _myEntity = value; DataContext = value; } } public EntityTabItem(string path) { this.MyEntity = new Entity(path); } static EntityTabItem() { DefaultStyleKeyProperty.OverrideMetadata(typeof(EntityTabItem), new FrameworkPropertyMetadata(typeof(EntityTabItem))); } } </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