Dragablz icon indicating copy to clipboard operation
Dragablz copied to clipboard

ToolTip Not Displaying Binding Field Correctly 'System.Windows.DataTemplate'

Open aherrick opened this issue 7 years ago • 9 comments

I have a basic Style setup like the following. I want to bind to Header property.

When I run the App, this is what I see for the ToolTip: System.Windows.DataTemplate

image

<Style TargetType="{x:Type dragablz:TabablzControl}" BasedOn="{StaticResource {x:Type dragablz:TabablzControl}}">
               <Setter Property="ItemContainerStyle" Value="{StaticResource TrapezoidDragableTabItemStyle}" />
               <Setter Property="AdjacentHeaderItemOffset" Value="-12" />
               <!--<Setter Property="NewItemFactory" Value="{x:Static local:MainWindowViewModel.NewItemFactory}" />-->
               <Setter Property="ShowDefaultAddButton" Value="True" />
               <Setter Property="ShowDefaultCloseButton" Value="True" />
               <Setter Property="ToolTip">
                   <Setter.Value>
                       <DataTemplate DataType="{x:Type local:TabContent}">
                           <TextBlock Text="{Binding Header}" />
                       </DataTemplate>
                   </Setter.Value>
               </Setter>
               <Setter Property="HeaderItemTemplate">
                   <Setter.Value>
                       <DataTemplate DataType="{x:Type local:TabContent}">
                           <TextBlock Text="{Binding Header}" Width="200" ToolTip="{Binding Header}" />
                       </DataTemplate>
                   </Setter.Value>
               </Setter>
               <Setter Property="ContentTemplate">
                   <Setter.Value>
                       <DataTemplate DataType="{x:Type local:TabContent}">
                           <ContentPresenter Margin="4" Content="{Binding Content}" />
                       </DataTemplate>
                   </Setter.Value>
               </Setter>
           </Style>

aherrick avatar Sep 21 '18 17:09 aherrick

Tooltip expects a string value, not a datatemplate. That's how WPF works. you will need anything else if you want do display more than text

jeremyVignelles avatar Sep 21 '18 19:09 jeremyVignelles

@jeremyVignelles I do just want to display text... however how can I just include a string value considering I'm using Data Binding?

I've tried something like this but it doesn't work.

<Setter Property="ToolTip" Value="{Binding Header}"/>

aherrick avatar Sep 24 '18 12:09 aherrick

It should work that way. It depends on what is your DataContext. You should have a message in the output window of Visual studio.

See also : https://www.wpf-tutorial.com/data-binding/debugging/

jeremyVignelles avatar Sep 24 '18 14:09 jeremyVignelles

It doesn't work that way as it has no context of the DataType:

See how HeaderItemTemplate and ContentTemplate are being set. When I just reference

<Setter Property="ToolTip" Value="{Binding Header}"/> It doesn't have:

<DataTemplate DataType="{x:Type local:TabContent}">

aherrick avatar Sep 24 '18 16:09 aherrick

Oh, I see where your problem is: You are trying to set a Tooltip on the TabablzControl itself, instead of each tab.

Try to remove this code:

               <Setter Property="ToolTip">
                   <Setter.Value>
                       <DataTemplate DataType="{x:Type local:TabContent}">
                           <TextBlock Text="{Binding Header}" />
                       </DataTemplate>
                   </Setter.Value>
               </Setter>

because <TextBlock Text="{Binding Header}" Width="200" ToolTip="{Binding Header}" /> should be enough. You will need to put your mouse on the text however.

You can also add a container around your text block that will hold the tooltip.

jeremyVignelles avatar Sep 24 '18 16:09 jeremyVignelles

Thanks for the thoughts but no, having ToolTip on the TextBlock doesn't display anything.

I'm only able to get the ToolTip to display anything is using the ToolTip Property.

Any thoughts how I can still use the property?

aherrick avatar Sep 24 '18 17:09 aherrick

Yeah, but then it would apply to the whole tabs collection, so that's not what you want.

You will want to do your work inside HeaderItemTemplate. try to wrap your text block inside a Grid or a Border with a background color and put your tooltip on that

jeremyVignelles avatar Sep 24 '18 18:09 jeremyVignelles

I'm trying something like you suggested but it's not working:

<Setter Property="HeaderItemTemplate">
                    <Setter.Value>
                        <DataTemplate DataType="{x:Type local:TabContent}">

                            <Grid Grid.Row="1" ToolTipService.ShowDuration="5000">
                                <TextBlock Text="{Binding Header}" Width="200" />

                                <Grid.ToolTip>
                                    <ToolTip>
                                        <TextBlock Text="{Binding Path=Header}" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" />
                                    </ToolTip>
                                </Grid.ToolTip>
                            </Grid>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>

aherrick avatar Sep 24 '18 18:09 aherrick

@jeremyVignelles Any thoughts here? This is the sample project I am basing my testing off. How would you get ToolTip to work here:

https://github.com/ButchersBoy/DragablzSamplez/blob/master/MahAppsWindowApp/App.xaml

aherrick avatar Sep 28 '18 14:09 aherrick