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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
<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: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>
</UserControl.Resources>
<Grid>
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Background="Transparent">
<ItemsControl Grid.Row="1" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=ParameterizedObject.Parameters}" HorizontalContentAlignment="Stretch">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding}" Padding="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=ItemPadding}" Margin="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=ItemMargin}" MinHeight="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=ItemMinHeight}">
<ContentControl.Style>
<Style TargetType="ContentControl">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}" Margin="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=ItemLabelMargin}"></TextBlock>
<TextBox Text="{Binding Value,UpdateSourceTrigger=PropertyChanged}"></TextBox>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
<Style.Resources>
<DataTemplate x:Key="slide">
<StackPanel>
<TextBlock Text="{Binding Name}" Margin="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=ItemLabelMargin}"></TextBlock>
<Slider Orientation="Horizontal" HorizontalAlignment="Stretch" Minimum="{Binding Minimum}" Maximum="{Binding Maximum}" Value="{Binding Value}" ToolTip="{Binding Value}"></Slider>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="slideInteger">
<StackPanel>
<TextBlock Text="{Binding Name}" Margin="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=ItemLabelMargin}"></TextBlock>
<Slider TickFrequency="1" IsSnapToTickEnabled="True" Orientation="Horizontal" HorizontalAlignment="Stretch" Minimum="{Binding Minimum}" Maximum="{Binding Maximum}" Value="{Binding Value,Converter={StaticResource DoubleToIntConverter}}"></Slider>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="numUpDown">
<Grid Margin="0 0 0 4" x:Name="grid">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center" Grid.Column="0" Text="{Binding Name}" Margin="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=ItemLabelMargin}"></TextBlock>
<local:ParameterItemNumericUpDownEditor Grid.Column="1" Minimum="-10000" Maximum="10000" Height="25" Value="{Binding RelativeSource={RelativeSource AncestorType=Grid},Path=DataContext.Value,Mode=TwoWay}"></local:ParameterItemNumericUpDownEditor>
</Grid>
</DataTemplate>
<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="chk">
<CheckBox Margin="0 5 0 5" IsChecked="{Binding Value}" Foreground="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=Foreground}" Content="{Binding Name}"></CheckBox>
</DataTemplate>
<DataTemplate x:Key="text">
<StackPanel>
<TextBlock Text="{Binding Name}" Margin="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=ItemLabelMargin}"></TextBlock>
<TextBox Text="{Binding Value,UpdateSourceTrigger=PropertyChanged}"></TextBox>
</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,FallbackValue={StaticResource slide},TargetNullValue={StaticResource slide}}"></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,FallbackValue={StaticResource numUpDown},TargetNullValue={StaticResource numUpDown}}"></Setter>
</MultiDataTrigger>
<DataTrigger Binding="{Binding Type}" Value="{x:Type sys:Int32}">
<Setter Property="ContentTemplate" Value="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=Int32Template,FallbackValue={StaticResource slideInteger},TargetNullValue={StaticResource slideInteger}}"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Type}" Value="{x:Type sys:Single}">
<Setter Property="ContentTemplate" Value="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=SingleTemplate,FallbackValue={StaticResource slide},TargetNullValue={StaticResource slide}}"></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,FallbackValue={StaticResource chk},TargetNullValue={StaticResource chk}}"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Type}" Value="{x:Type sys:String}">
<Setter Property="ContentTemplate" Value="{Binding RelativeSource={RelativeSource AncestorType=local:ParameterizedEditor},Path=StringTemplate,FallbackValue={StaticResource text},TargetNullValue={StaticResource text}}"></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>
</ScrollViewer>
</Grid>
</UserControl>
|