none
Adorner rather than style?

    Question

  • (This is a follow-up to my style question at http://social.msdn.microsoft.com/Forums/windowsserver/en-US/97f4e5a8-523e-4cd0-a8ec-3bc0fab8c832/style-all-labels-with-tooltips?forum=wpf.)

    If I'm using the wrong terminology, please forgive me, but please concentrate on the question.  :)  I have a style for my labels as follows:

    <Style TargetType="TextBlock" xmlns:local="clr-namespace:WpfApplication">
      <Style.Resources>
        <local:Converter x:Key="converter"/>
      </Style.Resources>
      <Style.Triggers>
        <DataTrigger Binding="{Binding ToolTip, RelativeSource={RelativeSource Self}, 
          Converter={StaticResource converter}}" Value="True">
          <Setter Property="Background" Value="Green"/>
        </DataTrigger>
      </Style.Triggers>
    </Style>
    

    I'd like to do this with an adorner instead, so that I'm not just changing the style, but changing the contents as well.  For example, I'd like to add an asterisk to the text, or something like that.  The following (a common "error" adorner) doesn't work, but shows my idea:

    <Setter Property="DockPanel">
      <TextBlock Foreground="Red" FontSize="20">!</TextBlock>
      <AdornedElementPlaceholder/>
    </Setter>
    

    Any ideas appreciated.  Thanks!

    Brad.

    Tuesday, March 25, 2014 12:13 AM

Answers

  • Hi,

    If I'm not misunderstanding, I think we can't implement your requirement by using AdornedElementPlaceholder, we'd better create a custom Label and change background with Converter:

    Here is my sample:

    <Window.Resources>
            <Style TargetType="Label" xmlns:local="clr-namespace:WpfApplication">
                <Style.Resources>
                    <local:Converter x:Key="converter"/>
                </Style.Resources>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <DockPanel>
                                <TextBlock Foreground="Red" FontSize="20">!</TextBlock>
                                <TextBlock Name="txb" Text="{TemplateBinding Label.Content}" Width="110" ToolTip="{TemplateBinding Label.ToolTip}" />
                            </DockPanel>
                            <ControlTemplate.Triggers>
                                <DataTrigger Binding="{Binding ToolTip, RelativeSource={RelativeSource Self},  Converter={StaticResource converter}}" Value="True">
                                    <Setter TargetName="txb" Property="Background" Value="Green" />
                                </DataTrigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                        
                    </Setter.Value>
                </Setter>
            </Style>
    </Window.Resources>
    <Grid>
            <Label x:Name="label1" ToolTip="Test Tooltip" Width="120" Height="30" FontSize="20" Content="Something" />
    </Grid>

    Screenshot:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Pletzky Wednesday, March 26, 2014 10:20 PM
    Wednesday, March 26, 2014 6:36 AM
    Moderator

All replies

  • http://drwpf.com/blog/category/tips-tricks/
    Tuesday, March 25, 2014 3:02 PM
  • Thanks for your response!  I took a look at that article, and sadly it got me no closer.

    Brad.

    Tuesday, March 25, 2014 8:57 PM
  • Hi,

    If I'm not misunderstanding, I think we can't implement your requirement by using AdornedElementPlaceholder, we'd better create a custom Label and change background with Converter:

    Here is my sample:

    <Window.Resources>
            <Style TargetType="Label" xmlns:local="clr-namespace:WpfApplication">
                <Style.Resources>
                    <local:Converter x:Key="converter"/>
                </Style.Resources>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <DockPanel>
                                <TextBlock Foreground="Red" FontSize="20">!</TextBlock>
                                <TextBlock Name="txb" Text="{TemplateBinding Label.Content}" Width="110" ToolTip="{TemplateBinding Label.ToolTip}" />
                            </DockPanel>
                            <ControlTemplate.Triggers>
                                <DataTrigger Binding="{Binding ToolTip, RelativeSource={RelativeSource Self},  Converter={StaticResource converter}}" Value="True">
                                    <Setter TargetName="txb" Property="Background" Value="Green" />
                                </DataTrigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                        
                    </Setter.Value>
                </Setter>
            </Style>
    </Window.Resources>
    <Grid>
            <Label x:Name="label1" ToolTip="Test Tooltip" Width="120" Height="30" FontSize="20" Content="Something" />
    </Grid>

    Screenshot:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Pletzky Wednesday, March 26, 2014 10:20 PM
    Wednesday, March 26, 2014 6:36 AM
    Moderator
  • Awesome!  That was exactly what I needed.

    Thanks!

    Brad.

    Wednesday, March 26, 2014 10:20 PM