Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WPF tooltip style with image - bind url

$
0
0

Hi,

I have a style i'm using for tooltips- it includes Image and some TextBlock in it (as ControlTemplate).

i would like to bind Image Source to one of my properties in the code behind- currently it's hard coded to "Images/Crab.png".

(already done successfully- bind TextBlock text to Content property)

any idea?

here's the code i wrote:

<Style x:Key="ToolTipInventoryTemplate" TargetType="ToolTip">
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="HasDropShadow" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToolTip">
                    <Border CornerRadius="7" HorizontalAlignment="Center" VerticalAlignment="Top" Padding="5" 
                            BorderThickness="3,3,3,3" >
                        <Border.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="Transparent" Offset="0"/>
                                <GradientStop Color="Transparent" Offset="1"/>
                            </LinearGradientBrush>
                        </Border.Background>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" />
                                <ColumnDefinition Width="80" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="80"/>
                                <RowDefinition Height="80"/>
                            </Grid.RowDefinitions>
                            <Image Source="Images/Crab.png" Grid.RowSpan="2" Grid.ColumnSpan="2" Margin="3" Stretch="Fill"/>
                            <TextBlock FontFamily="Tahoma" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Grid.RowSpan="2" FontSize="13" 
                                       Text="{TemplateBinding Content}" 
                                       Foreground="Black" TextWrapping="Wrap" FontWeight="ExtraBold" Margin="35"/>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>