How to Bind TextBlock Width when it is part of style
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?
Thank you so much
<Style BasedOn="{StaticResource {x:Type ComboBox}}" TargetType="{x:Type
src:AutoCompleteSearchControl}">
<Setter Property="IsEditable" Value="true"></Setter>
<Style.Triggers>
<Trigger Property="IsEditable" Value="True">
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Padding" Value="0,1"/>
<Setter Property="Template" Value="{StaticResource
AutoCompleteComboBoxEditableTemplate}"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Text" Value="" />
</MultiTrigger.Conditions>
<Setter Property="Background">
<Setter.Value>
<VisualBrush Stretch="None">
<VisualBrush.Visual>
<TextBlock Text="Press F12"
Margin="5,5,5,5"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Foreground="Gray"
Background="White"
FontSize="16" />
</VisualBrush.Visual>
</VisualBrush>
</Setter.Value>
</Setter>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Validate" Value="True"/>
<Condition Property="SelectedItem" Value="{x:Null}"/>
<Condition Property="IsEnabled" Value="True"/>
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="BorderThickness" Value="1"/>
</MultiTrigger.Setters>
</MultiTrigger>
</Style.Triggers>
</Style>
No comments:
Post a Comment