views:

35

answers:

2

Hi,

I have written a markup extension which stores amongst others a help text. This help text is shown on the right side of the main window. This works fine.

Now, I want to add a tooltip for every control. The content of the tooltip should be same as for the helptext extension.

The XAML code:

<ListView ctrl:ListViewLayoutManager.Enabled="true"
    x:Name="ListViewSources"
    ItemsSource="{Binding SourceItems}" 
    ItemContainerStyle="{DynamicResource ListViewItemStyleAlternate}"
    Height="150"
    MinWidth="350" 
    Helper:HelpExtension.IsControl="true"
    Helper:HelpExtension.HelpText="{x:Static strings:GUIResource.HelpProfilesSourcesDescriptionText}" >
 <ListView.ToolTip>
  <ToolTip Style="{DynamicResource Own_TooltipStyle}"></ToolTip>
 </ListView.ToolTip>

And now the code of the style:

 <Style x:Key="Own_TooltipStyle" TargetType="{x:Type ToolTip}">
  <Setter Property="Background" Value="LightYellow"/>
  <Setter Property="Template">
   <Setter.Value>
    <ControlTemplate TargetType="{x:Type ToolTip}">
     <Grid>
      <TextBlock Text="{Binding Path=Helper:HelpExtension.HelpText, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListView}}}" />
     </Grid>
    </ControlTemplate>
   </Setter.Value>
  </Setter>
 </Style>

If I run the program I get the binding error:

System.Windows.Data Error: 39 : BindingExpression path error: 'Helper:HelpExtension' property not found on 'object' ''ListView' (Name='ListViewSources')'. BindingExpression:Path=Helper:HelpExtension.HelpText; DataItem='ListView' (Name='ListViewSources'); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

Does anybody know how I can bind the TextBlock to the content of Helper:HelpExternsion.HelpText?

Thanks Dieter

A: 

Just put parentheses around the attached property name :

<TextBlock Text="{Binding Path=(Helper:HelpExtension.HelpText), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListView}}}" />
Thomas Levesque
A: 

Do you mean binding to attached property? In that case you need additional parentheses:

{Binding Path=(Helper:HelpExtension.HelpText), ...

See, for example, here.

Vlad