Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF custom style, pass binding parameter
    text
    copied!<p>I have such style in WPF</p> <pre><code> &lt;Style x:Key="SubTabItem" TargetType="{x:Type TabItem}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type TabItem}"&gt; &lt;ControlTemplate.Triggers&gt; &lt;DataTrigger Binding="{Binding Path=IsSelected}" Value="false"&gt; &lt;Setter Property="TabItem.IsEnabled" Value="false" /&gt; &lt;/DataTrigger&gt; &lt;/ControlTemplate.Triggers&gt; </code></pre> <p>I want to use it with my TabItem in such way</p> <pre><code> &lt;TabControl x:Name="configControl" Padding="0" Background="{x:Null}" BorderThickness="0" FocusVisualStyle= "{x:Null}" &gt; &lt;TabItem x:Name="MyName" Header="My Name" Visibility="Visible" Style="{DynamicResource SubTabItem}"&gt; &lt;/TabItem&gt; &lt;/TabControl&gt; </code></pre> <p>I assign configControl.DataContext in codebehind.</p> <p>When i use it in such way(with exact binding in ControlTemplate datatrigger) - it works. But I want to <em>PASS</em> the different binding path to the style, when using it in target item. As i understand i can do it through TemplateBinding but i can't find how?</p> <p>I can do several same styles with each binding defined, but i want to find a way how to simplify it, so i can write smth like this:</p> <pre><code> &lt;TabItem x:Name="MyName" Header="My Name" Visibility="Visible" Style="{DynamicResource SubTabItem}" Binding={Binding Path=IsSelected}&gt; &lt;/TabItem&gt; &lt;TabItem x:Name="MyName2" Header="My Name2" Visibility="Visible" Style="{DynamicResource SubTabItem}" Binding={Binding Path=IsThisSelected}&gt; &lt;/TabItem&gt; </code></pre> <p>so it take this paths and decide if to enable or disable each of this tab item based on passed value.</p>
 

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