timheuer / callisto

A control toolkit for Windows 8 XAML applications. Contains some UI controls to make it easier to create Windows UI style apps for the Windows Store in accordance with Windows UI guidelines.
http://timheuer.com/blog/archive/2012/05/31/introducing-callisto-a-xaml-toolkit-for-metro-apps.aspx
Other
338 stars 108 forks source link

accessing SettingsFlyout from SettingsFlyout.Content [ UserControl ] #142

Closed myusrn closed 11 years ago

myusrn commented 11 years ago

is there a way i can I access the callisto SettingsFlyout from SettingsFlyout.Content [ UserControl ]?

I was using (this.Parent as SettingsFlyout) but that is null sometimes and not other times.

I'm looking to do something like this from withing the settings flyout user control submit button handler.

(this.Parent as SettingsFlyout).IsOpen = false

similar to how in an html/js settings flyout I would execute SettingsFlyoutDiv.winControl.hide();

timheuer commented 11 years ago

The Parent of the UC wouldn't necessarily be the root SettingsFlyout element, but rather the container in the control template that houses it. You could walk the visual tree to find the ancestor that you want.

myusrn commented 11 years ago

Thanks for response. I guess the issue is that if the this.Parent and VisualTreeHelper.GetParent(this) both return null then walking up the visual tree is not going to be possible. Am I perhaps overlooking some other property that supports walking up the tree?

timheuer commented 11 years ago

You just have to find the right tree element. Using Callisto you could do:

SettingsFlyout sf = this.Ancestors<SettingsFlyout>().FirstOrDefault() as SettingsFlyout;
sf.IsOpen = false;