UI Virtualization problem with Q1 2012 SP1

4 posts, 0 answers
  1. David
    David avatar
    18 posts
    Member since:
    Apr 2016

    Posted 04 May Link to this post

    Hi, I have a gridview that can have configurable colums. Some of them use the default template, but others not. I have a problem with the ones that need to show icons.

     

    Here is a sample of a datatemplate of a GridViewCell:

     

    <DataTemplate x:Key="IconFlagsCellTemplate">
        <StackPanel Name="IconFlagsCellTemplate" Orientation="Horizontal" DataContext="{Binding Blockings, Converter={StaticResource IconFlagsConverter}}">
            <Image Source="{StaticResource BlockingTechnicalOffice16x16}" Visibility="{Binding TechnicalOffice, Converter={StaticResource Boolean2VisibilityConverter}}"/>
     
     
        </StackPanel>
    </DataTemplate>

     

    This works ok. The problem comes, for example, when I try to assing a tooltip:

    <DataTemplate x:Key="IconFlagsCellTemplate">
        <StackPanel Name="IconFlagsCellTemplate" Orientation="Horizontal" DataContext="{Binding Blockings, Converter={StaticResource IconFlagsConverter}}">
     
            <Image Source="{StaticResource BlockingTechnicalOffice16x16}" ToolTip="{lex:Loc BudgetBlockingTooltip_TECHNICAL_OFFICE}"
                Visibility="{Binding TechnicalOffice, Converter={StaticResource Boolean2VisibilityConverter}}"/>
     
        </StackPanel>
    </DataTemplate>

    I receive the next error when I scroll horizontally and the cell is going out of scope, the moment that I think the control will recycle the cell:

    System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.FrameworkElement', AncestorLevel='1''. BindingExpression:Path=Parent; DataItem=null; target element is 'StackPanel' (Name='IconFlagsCellTemplate'); target property is 'Parent' (type 'DependencyObject')

     

    Also this produces that the horizontal scroll pauses a little bit when giving those errors, causing a notieceable visual delay.

    But there is more. I need the image to be wrapped into a button, as I need to add a contextual menu to the button and some triggers, but this also produces the avobe error, no matter if there is tooltip or not. Fortunately, if instead of the button I put a ContentControl, but not tooltip, there is no problem as well.

     

    I need, though, both tooltip and custom menu. And also there is need to keep into account that there will not be only an icon. There could be any number of icons, that will be shown or not depending on some ViewModel condition, as you can see with the bindings.

     

    Hope anybody could help me by providing a working solution, as the client is complaining about the scrolling issue. Meanwhile I'll try to test other ways of doing things.

     

    Thanks in advance.

     

    David.

     

     

  2. David
    David avatar
    18 posts
    Member since:
    Apr 2016

    Posted 04 May in reply to David Link to this post

    I've found an issue that allows me to use tooltips. I was using WPFLocalizationExtension, and some special markup for it. If instead of using it I do the translation in codebehind in the Load event of the image, I can set the tooltip without problem.

    I will update this thread when I find a complete solution.

  3. UI for WPF is Visual Studio 2017 Ready
  4. David
    David avatar
    18 posts
    Member since:
    Apr 2016

    Posted 05 May in reply to David Link to this post

    Finally I could manage in doing what I wanted:

     

    <ContentControl Style="{StaticResource CellIconContentControlStyle}" Tag="{x:Static model:BlockingFlags.TECHNICAL_OFFICE}"
        Visibility="{Binding TechnicalOffice, Converter={StaticResource Boolean2VisibilityConverter}}">
        <Image Style="{StaticResource CellIconContentImageStyle}" Loaded="IconImage_Loaded"
            Source="{StaticResource BlockingTechnicalOffice16x16}" Tag="BudgetBlockingTooltip_TECHNICAL_OFFICE"/>
    </ContentControl>

     

    Above is how I specify the icon inside the gridview. In the Loaded event the translation is done. I am using tag, but I think I will change it for tooltip in case I need tag in the future.

     

     

     

  5. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 05 May Link to this post

    Hello,

    I am glad to hear that you could resolve the problem by yourself. 

    Regards,
    Yoan
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top