Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable all binding/triggering inside a ContentControl

In this case I have a Grid with a lot controls inside it , buttons, canvas, drawing, animations , all bound to view-models, I would like to disable all the dataTriggers, triggers , bindings inside its children and children of children, etc., when I set the visibility of the Grid to collapsed, so it is not wasting CPU cycles, (because a heavy animation is continuously running), and not crashing!

I'm using a behaviour: http://www.microsoft.com/design/toolbox/tutorials/pathlistbox/carousel.aspx

but it seems to have a bug that its making the app crash if the listbox is collapsed when using it, So I need to disable the databinding which activates the behaviour,

from what I found: Does Visibility = IsCollapsed skip the data-binding part?

  • Your controls' Templates will not be applied

So the only way to do it is putting everything inside a controltemplate:

<ContentControl  Visibility="Collapsed">
    <ContentControl.Template>
        <Grid Name="Heavy Animation control">
            <!--- animations, triggers, bindings ,  -->
        </Grid>
    </ContentControl.Template>

So in this way the Template wouldn't be applied and everything would be off until I switch the visibility.

So my question is: is this the correct way to address this issue?

like image 737
elios264 Avatar asked Nov 11 '22 12:11

elios264


1 Answers

Yes. Since the ContentControl is collapsed, the template will not be applied until you change the visibility to visible.

However, I would be interested in knowing how your grid is set up and whether you could break it down a bit more so that the buttons, canvas, drawing, animations, etc. are only initialized as they are needed.

like image 54
kleineg Avatar answered Nov 15 '22 05:11

kleineg