AgainMe AgainMe - 1 year ago 113
C# Question

How to get the DataContext of VisualParent?

I've a

with this structure:

private void ToggleButton_Checked(object sender, System.Windows.RoutedEventArgs e)
//store settings

I need to get the details of
, in particular the
, how can I do this? Thanks.


The xaml structure is this:

<ToggleButton Focusable="False" Width="19" Height="19" IsChecked="{Binding Path = IsFavourite}"
Checked="ToggleButton_Checked" Unchecked="ToggleButton_Unchecked">

Answer Source
((sender as System.Windows.Controls.Primitives.ToggleButton).Parent as Grid).DataContext

Instead of grid you can have a different control. So replace that as per your xaml structure.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download