[reflection] Coop handles icalls in System.Reflection and System.RuntimeTypeHandle...
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / ExpandButtonVisibilityConverter.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.Activities.Presentation
6 {
7     using System.Diagnostics;
8     using System.Globalization;
9     using System.Windows.Data;
10     using System.Activities.Presentation.Model;
11     using System.Activities.Presentation.Internal.PropertyEditing.Model;
12     using System.Windows;
13     using System.Activities.Presentation.View;
14     using System.Runtime;
15
16     internal class ExpandButtonVisibilityConverter : IMultiValueConverter
17     {
18
19         public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
20         {
21             bool isRootDesigner = true;
22             if (values[0] is bool)
23             {
24                 isRootDesigner = (bool)values[0];
25             }
26             ModelItem modelItem = values[1] as ModelItem;
27             WorkflowViewElement viewElement = values[2] as WorkflowViewElement;
28             Fx.Assert(viewElement != null, "TemplatedParent should be of type WorkflowViewElement");
29             return GetExpandCollapseButtonVisibility(viewElement);
30         }
31
32         public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
33         {
34             throw FxTrace.Exception.AsError(new NotSupportedException());
35         }
36
37         public static Visibility GetExpandCollapseButtonVisibility(WorkflowViewElement viewElement)
38         {
39             ActivityDesigner designer = viewElement as ActivityDesigner;
40             bool hasDelegates = (designer != null) && designer.HasActivityDelegates;
41
42             Visibility visibility = Visibility.Visible;
43             if (viewElement == null || viewElement.IsRootDesigner || viewElement.DoesParentAlwaysExpandChild() ||
44                 viewElement.DoesParentAlwaysCollapseChildren() || (viewElement.Content == null && !hasDelegates) ||
45                 !viewElement.Collapsible || !(viewElement is ActivityDesigner))
46             {
47                 visibility = Visibility.Collapsed;
48             }
49             return visibility;
50         }
51
52     }
53 }