void SetImplicitStyles(ImplicitStyleMask style_mask, Style[] styles) { IntPtr styles_array = Marshal.AllocHGlobal(IntPtr.Size * styles.Length); for (int i = 0; i < styles.Length; i++) { Marshal.WriteIntPtr(styles_array, i * IntPtr.Size, styles[i] == null ? IntPtr.Zero : styles[i].native); } NativeMethods.framework_element_set_implicit_styles(native, style_mask, styles_array); }
void get_implicit_styles_cb_safe(IntPtr fwe_ptr, ImplicitStyleMask style_mask, out IntPtr styles_array) { styles_array = IntPtr.Zero; try { var fwe = NativeDependencyObjectHelper.FromIntPtr(fwe_ptr) as FrameworkElement; if (fwe != null) { get_implicit_styles_cb(fwe, style_mask, out styles_array); } } catch (Exception ex) { try { Console.WriteLine("Moonlight: Unhandled exception in Application.get_implicit_styles_cb_safe: {0}", ex); } catch { } } }
void get_implicit_styles_cb(FrameworkElement fwe, ImplicitStyleMask style_mask, out IntPtr styles_array) { Type fwe_type = fwe.GetType(); string fwe_type_string = fwe_type.ToString(); Style generic_xaml_style = null; Style app_resources_style = null; Style visual_tree_style = null; if ((style_mask & ImplicitStyleMask.GenericXaml) != 0) { // start with the lowest priority, the // generic.xaml style, only valid for // controls, as it requires DefaultStyleKey. Control control = fwe as Control; if (control != null) { Type style_key = control.DefaultStyleKey as Type; if (style_key != null) { generic_xaml_style = GetGenericXamlStyleFor(style_key); } } } if ((style_mask & ImplicitStyleMask.ApplicationResources) != 0) { // next try the application's resources. // these affect all framework elements, // whether inside templates or out. app_resources_style = (Style)Resources[fwe_type]; if (app_resources_style == null) { app_resources_style = (Style)Resources[fwe_type_string]; } } if ((style_mask & ImplicitStyleMask.VisualTree) != 0) { // highest priority, the visual tree FrameworkElement el = fwe; bool fwe_is_control = fwe is Control; while (el != null) { // if the frameworkelement was defined outside of a template and we hit a containing // template (e.g. if the FWE is in the Content of a ContentControl) we need to skip // the intervening elements in the visual tree, until we hit more user elements. if (el.TemplateOwner != null && fwe.TemplateOwner == null) { el = el.TemplateOwner as FrameworkElement; continue; } // for non-controls, we limit the implicit style scope to that of the template. if (!fwe_is_control && el == fwe.TemplateOwner) { break; } visual_tree_style = (Style)el.Resources[fwe_type]; if (visual_tree_style != null) { break; } visual_tree_style = (Style)el.Resources[fwe_type_string]; if (visual_tree_style != null) { break; } el = VisualTreeHelper.GetParent(el) as FrameworkElement; } } styles_array = Marshal.AllocHGlobal((int)ImplicitStyleIndex.Count * IntPtr.Size); Marshal.WriteIntPtr(styles_array, (int)ImplicitStyleIndex.GenericXaml * IntPtr.Size, (generic_xaml_style != null) ? generic_xaml_style.native : IntPtr.Zero); Marshal.WriteIntPtr(styles_array, (int)ImplicitStyleIndex.ApplicationResources * IntPtr.Size, (app_resources_style != null) ? app_resources_style.native : IntPtr.Zero); Marshal.WriteIntPtr(styles_array, (int)ImplicitStyleIndex.VisualTree * IntPtr.Size, (visual_tree_style != null) ? visual_tree_style.native : IntPtr.Zero); }
void ClearImplicitStyles(ImplicitStyleMask style_mask) { NativeMethods.framework_element_clear_implicit_styles(native, style_mask); }
void get_implicit_styles_cb (FrameworkElement fwe, ImplicitStyleMask style_mask, out IntPtr styles_array) { Type fwe_type = fwe.GetType(); string fwe_type_string = fwe_type.ToString(); Style generic_xaml_style = null; Style app_resources_style = null; Style visual_tree_style = null; if ((style_mask & ImplicitStyleMask.GenericXaml) != 0) { // start with the lowest priority, the // generic.xaml style, only valid for // controls, as it requires DefaultStyleKey. Control control = fwe as Control; if (control != null) { Type style_key = control.DefaultStyleKey as Type; if (style_key != null) { generic_xaml_style = GetGenericXamlStyleFor (style_key); } } } if ((style_mask & ImplicitStyleMask.ApplicationResources) != 0) { // next try the application's resources. // these affect all framework elements, // whether inside templates or out. app_resources_style = (Style)Resources[fwe_type]; if (app_resources_style == null) app_resources_style = (Style)Resources[fwe_type_string]; } if ((style_mask & ImplicitStyleMask.VisualTree) != 0) { // highest priority, the visual tree FrameworkElement el = fwe; bool fwe_is_control = fwe is Control; while (el != null) { // if the frameworkelement was defined outside of a template and we hit a containing // template (e.g. if the FWE is in the Content of a ContentControl) we need to skip // the intervening elements in the visual tree, until we hit more user elements. if (el.TemplateOwner != null && fwe.TemplateOwner == null) { el = el.TemplateOwner as FrameworkElement; continue; } // for non-controls, we limit the implicit style scope to that of the template. if (!fwe_is_control && el == fwe.TemplateOwner) break; visual_tree_style = (Style)el.Resources[fwe_type]; if (visual_tree_style != null) break; visual_tree_style = (Style)el.Resources[fwe_type_string]; if (visual_tree_style != null) break; el = VisualTreeHelper.GetParent (el) as FrameworkElement; } } styles_array = Marshal.AllocHGlobal ((int)ImplicitStyleIndex.Count * IntPtr.Size); Marshal.WriteIntPtr (styles_array, (int)ImplicitStyleIndex.GenericXaml * IntPtr.Size, (generic_xaml_style != null) ? generic_xaml_style.native : IntPtr.Zero); Marshal.WriteIntPtr (styles_array, (int)ImplicitStyleIndex.ApplicationResources * IntPtr.Size, (app_resources_style != null) ? app_resources_style.native : IntPtr.Zero); Marshal.WriteIntPtr (styles_array, (int)ImplicitStyleIndex.VisualTree * IntPtr.Size, (visual_tree_style != null) ? visual_tree_style.native : IntPtr.Zero); }
void get_implicit_styles_cb_safe (IntPtr fwe_ptr, ImplicitStyleMask style_mask, out IntPtr styles_array) { styles_array = IntPtr.Zero; try { var fwe = NativeDependencyObjectHelper.FromIntPtr (fwe_ptr) as FrameworkElement; if (fwe != null) get_implicit_styles_cb (fwe, style_mask, out styles_array); } catch (Exception ex) { try { Console.WriteLine ("Moonlight: Unhandled exception in Application.get_implicit_styles_cb_safe: {0}", ex); } catch { } } }