aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.SharedUI/Editors/ParameterizedEditor.xaml
blob: 679b9f95383d845487102a5e8ca517c714eb9bc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<UserControl x:Class="Tango.SharedUI.Editors.ParameterizedEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Tango.SharedUI.Editors"
             xmlns:dragAndDrop="clr-namespace:Tango.DragAndDrop;assembly=Tango.DragAndDrop"
             xmlns:converters="clr-namespace:Tango.SharedUI.Converters"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="200">

    <UserControl.Resources>
        <converters:EnumToItemsSourceConverter x:Key="EnumToItemsSourceConverter"></converters:EnumToItemsSourceConverter>
        <converters:IsEnumConverter x:Key="IsEnumConverter"></converters:IsEnumConverter>
        <converters:ParameterItemEditorTypeToEditorConverter x:Key="ParameterItemEditorTypeToEditorConverter"></converters:ParameterItemEditorTypeToEditorConverter>
        <converters:DoubleToIntConverter x:Key="DoubleToIntConverter"></converters:DoubleToIntConverter>
        <converters:IsNullConverter x:Key="IsNullConverter"></converters:IsNullConverter>

        <DataTemplate x:Key="nullTemplate">
            <Rectangle HorizontalAlignment="Stretch" Height="0" StrokeThickness="0" VerticalAlignment="Top" />
        </DataTemplate>
    </UserControl.Resources>

    <Grid>
        <ItemsControl x:Name="itemsControl" ItemsPanel="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=ItemsPanel}" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=Parameters}" HorizontalContentAlignment="Stretch">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <ContentControl Content="{Binding}" Focusable="False">
                        <ContentControl.Style>
                            <Style TargetType="ContentControl">
                                <Setter Property="ContentTemplate" Value="{StaticResource nullTemplate}">

                                </Setter>
                                <Style.Resources>
                                    <DataTemplate x:Key="enum">
                                        <StackPanel Margin="0 0 0 4">
                                            <TextBlock Text="{Binding Name}" Margin="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=ItemLabelMargin}"></TextBlock>
                                            <ComboBox Foreground="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=Foreground}" ItemsSource="{Binding Type,Converter={StaticResource EnumToItemsSourceConverter},Mode=OneTime}" SelectedValue="{Binding Value}" SelectedValuePath="Value" DisplayMemberPath="DisplayName"></ComboBox>
                                        </StackPanel>
                                    </DataTemplate>
                                    <DataTemplate x:Key="custom">
                                        <StackPanel>
                                            <TextBlock Text="{Binding Name}" Margin="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=ItemLabelMargin}"></TextBlock>
                                            <ContentPresenter>
                                                <ContentPresenter.Content>
                                                    <MultiBinding Converter="{StaticResource ParameterItemEditorTypeToEditorConverter}">
                                                        <Binding Path="DataContext" RelativeSource="{RelativeSource AncestorType=StackPanel}"></Binding>
                                                        <Binding Path="ParameterizedObject" RelativeSource="{RelativeSource AncestorType=local:ParameterizedEditor}"></Binding>
                                                    </MultiBinding>
                                                </ContentPresenter.Content>
                                            </ContentPresenter>
                                        </StackPanel>
                                    </DataTemplate>
                                </Style.Resources>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Type}" Value="{x:Type sys:Double}">
                                        <Setter Property="ContentTemplate" Value="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=DoubleTemplate,TargetNullValue={StaticResource nullTemplate}}"></Setter>
                                    </DataTrigger>
                                    <MultiDataTrigger>
                                        <MultiDataTrigger.Conditions>
                                            <Condition Binding="{Binding Type}" Value="{x:Type sys:Double}"></Condition>
                                            <Condition Binding="{Binding Maximum,Converter={StaticResource IsNullConverter}}" Value="True"></Condition>
                                            <Condition Binding="{Binding Minimum,Converter={StaticResource IsNullConverter}}" Value="True"></Condition>
                                        </MultiDataTrigger.Conditions>
                                        <Setter Property="ContentTemplate" Value="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=DoubleUpDownTemplate,TargetNullValue={StaticResource nullTemplate}}"></Setter>
                                    </MultiDataTrigger>
                                    <DataTrigger Binding="{Binding Type}" Value="{x:Type sys:Int32}">
                                        <Setter Property="ContentTemplate" Value="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=Int32Template,TargetNullValue={StaticResource nullTemplate}}"></Setter>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Type}" Value="{x:Type sys:Single}">
                                        <Setter Property="ContentTemplate" Value="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=SingleTemplate,TargetNullValue={StaticResource nullTemplate}}"></Setter>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Type,Converter={StaticResource IsEnumConverter}}" Value="True">
                                        <Setter Property="ContentTemplate" Value="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=EnumTemplate,FallbackValue={StaticResource enum},TargetNullValue={StaticResource enum}}"></Setter>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Type}" Value="{x:Type sys:Boolean}">
                                        <Setter Property="ContentTemplate" Value="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=BooleanTemplate,TargetNullValue={StaticResource nullTemplate}}"></Setter>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Type}" Value="{x:Type sys:String}">
                                        <Setter Property="ContentTemplate" Value="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=StringTemplate,TargetNullValue={StaticResource nullTemplate}}"></Setter>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding HasCustomEditor}" Value="True">
                                        <Setter Property="ContentTemplate" Value="{StaticResource custom}"></Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ContentControl.Style>
                    </ContentControl>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

        <dragAndDrop:DraggingSurface x:Name="draggingSurface" ClipToBounds="True" />
    </Grid>
</UserControl>