Skip to content

Commit ddeb2ba

Browse files
committed
reinstate some snippets
1 parent 2b0cf7b commit ddeb2ba

File tree

10 files changed

+884
-0
lines changed

10 files changed

+884
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+

2+
using System;
3+
using System.Windows;
4+
using System.Collections;
5+
using System.Windows.Media;
6+
using System.Windows.Controls;
7+
using System.Windows.Shapes;
8+
using System.Windows.Navigation;
9+
using System.Text;
10+
11+
namespace SDKSample {
12+
public partial class XAMLAPP{
13+
void ReportState(object sender, EventArgs e)
14+
{
15+
StringBuilder sb = new StringBuilder();
16+
TextBlock tb = new TextBlock();
17+
//<SnippetGetMetadataInit>
18+
PropertyMetadata pm;
19+
//</SnippetGetMetadataInit>
20+
sb.Append("MyStateControl State default = ");
21+
//<SnippetGetMetadataType>
22+
pm = MyStateControl.StateProperty.GetMetadata(typeof(MyStateControl));
23+
//</SnippetGetMetadataType>
24+
sb.Append(pm.DefaultValue.ToString());
25+
sb.Append("\n");
26+
sb.Append("UnrelatedStateControl State default = ");
27+
//<SnippetGetMetadataDOType>
28+
DependencyObjectType dt = unrelatedInstance.DependencyObjectType;
29+
pm = UnrelatedStateControl.StateProperty.GetMetadata(dt);
30+
//</SnippetGetMetadataDOType>
31+
sb.Append(pm.DefaultValue.ToString());
32+
sb.Append("\n");
33+
sb.Append("MyAdvancedStateControl State default = ");
34+
//<SnippetGetMetadataDOInstance>
35+
pm = MyAdvancedStateControl.StateProperty.GetMetadata(advancedInstance);
36+
//</SnippetGetMetadataDOInstance>
37+
sb.Append(pm.GetType().ToString());
38+
sb.Append("\n");
39+
//</SnippetDefaultMetadataDOInstance>
40+
tb.Text = sb.ToString();
41+
root.Children.Add(tb);
42+
}
43+
void NavPage2(object sender, RoutedEventArgs e)
44+
{
45+
Application currentApp = Application.Current;
46+
NavigationWindow nw = currentApp.Windows[0] as NavigationWindow;
47+
nw.Source = new Uri("page2.xaml", UriKind.RelativeOrAbsolute);
48+
}
49+
}
50+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+

2+
using System;
3+
using System.Windows;
4+
using System.Collections;
5+
using System.Windows.Media;
6+
using System.Windows.Controls;
7+
using System.Windows.Shapes;
8+
using System.Windows.Controls.Primitives;
9+
using System.Text;
10+
using System.Windows.Media.Animation;
11+
12+
namespace SDKSample {
13+
public partial class XAMLAPPPage2{
14+
void OnDPSelectionChanged(object sender, SelectionChangedEventArgs e)
15+
{
16+
ListBoxItem selected = (ListBoxItem) e.AddedItems[0]; // we won't handle multiselect
17+
PropertyMetadata pm;
18+
DependencyProperty dp = null;
19+
switch (selected.Content.ToString())
20+
{
21+
case ("ToggleButton.IsChecked"):
22+
dp = ToggleButton.IsCheckedProperty;
23+
break;
24+
case("Control.Background"):
25+
dp = Control.BackgroundProperty;
26+
break;
27+
case ("Storyboard.TargetName"):
28+
dp = Storyboard.TargetNameProperty;
29+
break;
30+
case ("FrameworkElement.DataContext"):
31+
dp = FrameworkElement.DataContextProperty;
32+
break;
33+
case ("FrameworkElement.Margin"):
34+
dp = FrameworkElement.MarginProperty;
35+
break;
36+
case ("ToolBar.Orientation"):
37+
dp = ToolBar.OrientationProperty;
38+
break;
39+
case ("UIElement.Visibility"):
40+
dp = UIElement.VisibilityProperty;
41+
break;
42+
}
43+
//<SnippetDPProps>
44+
//<SnippetDPGetMetadataSingle>
45+
pm = dp.GetMetadata(dp.OwnerType);
46+
//</SnippetDPGetMetadataSingle>
47+
MetadataClass.Text = pm.GetType().Name;
48+
TypeofPropertyValue.Text = dp.PropertyType.Name;
49+
DefaultPropertyValue.Text = (pm.DefaultValue!=null) ? pm.DefaultValue.ToString() : "null";
50+
HasCoerceValue.Text = (pm.CoerceValueCallback == null) ? "No" : pm.CoerceValueCallback.Method.Name;
51+
HasPropertyChanged.Text = (pm.PropertyChangedCallback == null) ? "No" : pm.PropertyChangedCallback.Method.Name;
52+
ReadOnly.Text = (dp.ReadOnly) ? "Yes" : "No";
53+
//</SnippetDPProps>
54+
//<SnippetFPMProperties>
55+
FrameworkPropertyMetadata fpm = pm as FrameworkPropertyMetadata;
56+
if (fpm!=null) {
57+
AffectsArrange.Text = (fpm.AffectsArrange) ? "Yes" : "No";
58+
AffectsMeasure.Text = (fpm.AffectsMeasure) ? "Yes" : "No";
59+
AffectsRender.Text = (fpm.AffectsRender) ? "Yes" : "No";
60+
Inherits.Text = (fpm.Inherits) ? "Yes" : "No";
61+
IsDataBindingAllowed.Text = (fpm.IsDataBindingAllowed) ? "Yes" : "No";
62+
BindsTwoWayByDefault.Text = (fpm.BindsTwoWayByDefault) ? "Yes" : "No";
63+
}
64+
//</SnippetFPMProperties>
65+
else
66+
{
67+
AffectsArrange.Text = "N/A";
68+
AffectsMeasure.Text = "N/A";
69+
AffectsRender.Text = "N/A";
70+
Inherits.Text = "N/A";
71+
IsDataBindingAllowed.Text = "N/A";
72+
BindsTwoWayByDefault.Text = "N/A";
73+
}
74+
//<SnippetDPDefaultValue>
75+
PropertyMetadata pmDefault = dp.DefaultMetadata;
76+
//</SnippetDPDefaultValue>
77+
}
78+
//<SnippetTrySetValue>
79+
void TrySetValue(DependencyObject target, DependencyProperty dp, object providedValue) {
80+
if (dp.IsValidType(providedValue))
81+
{
82+
target.SetValue(dp, providedValue);
83+
}
84+
}
85+
//</SnippetTrySetValue>
86+
//<SnippetTrySetValueWithValidate>
87+
void TrySetValueWithValidate(DependencyObject target, DependencyProperty dp, object providedValue)
88+
{
89+
if (dp.IsValidValue(providedValue))
90+
{
91+
target.SetValue(dp, providedValue);
92+
}
93+
}
94+
//</SnippetTrySetValueWithValidate>
95+
}
96+
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<Application x:Class="ColorPickerApp.MyApp"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
Startup="AppStartup"
5+
xmlns:local="clr-namespace:ColorPickerLib;assembly=ColorPickerLib"
6+
xmlns:app="clr-namespace:ColorPickerApp">
7+
8+
<Application.Resources>
9+
10+
<local:ColorBrushConverter x:Key="ColorBrushConverter"/>
11+
<local:ByteDoubleConverter x:Key="ByteDoubleConverter"/>
12+
13+
<!--
14+
This Converter is defined in MyApp.xaml.cs
15+
Notice the ?Mapping? at the top used to import the ColorPickerApp ClrNamespace and the associated xmlns:app.
16+
-->
17+
<app:ColorGradientConverter x:Key="ColorGradientConverter"/>
18+
19+
<!--<SnippetSetterValueRef>-->
20+
21+
<!--<SnippetDefaultStyleKeyAsSetter>-->
22+
<Style x:Key="Slider_RepeatButton" TargetType="{x:Type RepeatButton}">
23+
<Setter Property="OverridesDefaultStyle" Value="true" />
24+
<!--</SnippetDefaultStyleKeyAsSetter>-->
25+
<Setter Property="IsTabStop" Value="false" />
26+
<Setter Property="Focusable" Value="false" />
27+
<Setter Property="Template">
28+
<Setter.Value>
29+
<ControlTemplate TargetType="{x:Type RepeatButton}">
30+
<Border Background="Transparent" />
31+
</ControlTemplate>
32+
</Setter.Value>
33+
</Setter>
34+
<!--<SnippetDefaultStyleKeyAsSetter2>-->
35+
</Style>
36+
<!--</SnippetDefaultStyleKeyAsSetter2>-->
37+
38+
<!--</SnippetSetterValueRef>-->
39+
40+
<!--<SnippetStyleTargetNameRef>-->
41+
<Style x:Key="Slider_Thumb" TargetType="{x:Type Thumb}">
42+
<Setter Property="OverridesDefaultStyle" Value="true" />
43+
<Setter Property="Width" Value="14" />
44+
<Setter Property="Height" Value="14" />
45+
<Setter Property="Template">
46+
<Setter.Value>
47+
<ControlTemplate TargetType="{x:Type Thumb}">
48+
<Grid Width="14" Height="14">
49+
<Ellipse Fill="{TemplateBinding Foreground}" />
50+
<Ellipse Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1" x:Name="ThumbCover" >
51+
<Ellipse.Fill>
52+
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
53+
<LinearGradientBrush.GradientStops>
54+
<GradientStop Color="#CCFFFFFF" Offset="0" />
55+
<GradientStop Color="#00000000" Offset=".5" />
56+
<GradientStop Color="#66000000" Offset="1" />
57+
</LinearGradientBrush.GradientStops>
58+
</LinearGradientBrush>
59+
</Ellipse.Fill>
60+
</Ellipse>
61+
</Grid>
62+
<ControlTemplate.Triggers>
63+
<Trigger Property="IsDragging" Value="true">
64+
<Setter TargetName="ThumbCover" Property="Fill">
65+
<Setter.Value>
66+
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
67+
<LinearGradientBrush.GradientStops>
68+
<GradientStop Color="#CCFFFFFF" Offset="1" />
69+
<GradientStop Color="#00000000" Offset=".5" />
70+
<GradientStop Color="#66000000" Offset="0" />
71+
</LinearGradientBrush.GradientStops>
72+
</LinearGradientBrush>
73+
</Setter.Value>
74+
</Setter>
75+
</Trigger>
76+
</ControlTemplate.Triggers>
77+
</ControlTemplate>
78+
</Setter.Value>
79+
</Setter>
80+
</Style>
81+
<!--</SnippetStyleTargetNameRef>-->
82+
83+
<Style x:Key="Slider_CustomStyle" TargetType="{x:Type Slider}">
84+
<Setter Property="OverridesDefaultStyle" Value="true" />
85+
<Setter Property="Height" Value="14" />
86+
<Setter Property="Width" Value="80"/>
87+
<Setter Property="Margin" Value="1"/>
88+
<Setter Property="Orientation" Value="Horizontal"/>
89+
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
90+
<Setter Property="Minimum" Value="0"/>
91+
<Setter Property="Maximum" Value="255"/>
92+
<Setter Property="SmallChange" Value="1"/>
93+
<Setter Property="LargeChange" Value="51"/>
94+
<Setter Property="IsMoveToPointEnabled" Value="true"/>
95+
<Setter Property="Template">
96+
<Setter.Value>
97+
<ControlTemplate TargetType="{x:Type Slider}">
98+
<Grid ClipToBounds="false">
99+
<Border Height="6" CornerRadius="3" Background="{TemplateBinding Background}"
100+
BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1"
101+
Width="{TemplateBinding Width}"/>
102+
<Track Name="PART_Track">
103+
<Track.DecreaseRepeatButton>
104+
<RepeatButton Style="{StaticResource Slider_RepeatButton}"
105+
Command="Slider.DecreaseLarge"/>
106+
</Track.DecreaseRepeatButton>
107+
<Track.IncreaseRepeatButton>
108+
<RepeatButton Style="{StaticResource Slider_RepeatButton}"
109+
Command="Slider.IncreaseLarge"/>
110+
</Track.IncreaseRepeatButton>
111+
<Track.Thumb>
112+
<Thumb x:Name="Thumb"
113+
Style="{StaticResource Slider_Thumb}"/>
114+
</Track.Thumb>
115+
</Track>
116+
</Grid>
117+
</ControlTemplate>
118+
</Setter.Value>
119+
</Setter>
120+
</Style>
121+
122+
<LinearGradientBrush x:Key="BorderBackground" EndPoint="0,1" StartPoint="0,0">
123+
<LinearGradientBrush.GradientStops>
124+
<GradientStop Color="#77FFFFFF" Offset="0" />
125+
<GradientStop Color="#00FFFFFF" Offset=".15" />
126+
<GradientStop Color="#00000000" Offset=".85" />
127+
<GradientStop Color="#33000000" Offset="1" />
128+
</LinearGradientBrush.GradientStops>
129+
</LinearGradientBrush>
130+
131+
<LinearGradientBrush x:Key="BorderBrush" EndPoint="0,1" StartPoint="0,0">
132+
<LinearGradientBrush.GradientStops>
133+
<GradientStop Color="#99cccccc" Offset="0" />
134+
<GradientStop Color="#99666666" Offset="1" />
135+
</LinearGradientBrush.GradientStops>
136+
</LinearGradientBrush>
137+
138+
<Style x:Key="ColorPicker_CoolStyle" TargetType="{x:Type local:ColorPicker}">
139+
<Setter Property="Template">
140+
<Setter.Value>
141+
<ControlTemplate TargetType="{x:Type local:ColorPicker}">
142+
143+
<Border CornerRadius="5" Background="{TemplateBinding Background}" HorizontalAlignment="Center" VerticalAlignment="Center">
144+
<Border BorderThickness="1" CornerRadius="5" Background="{StaticResource BorderBackground}" Padding="3">
145+
146+
<Grid>
147+
<Grid.ColumnDefinitions>
148+
<ColumnDefinition/>
149+
<ColumnDefinition/>
150+
</Grid.ColumnDefinitions>
151+
152+
<Grid.RowDefinitions>
153+
<RowDefinition/>
154+
<RowDefinition/>
155+
<RowDefinition/>
156+
</Grid.RowDefinitions>
157+
158+
<Slider Grid.Column="0" Grid.Row="0" Foreground="red" Style="{StaticResource Slider_CustomStyle}"
159+
Value="{Binding Path=Red, Converter={StaticResource ByteDoubleConverter}, RelativeSource={RelativeSource TemplatedParent}}"
160+
Background="{Binding Path=Color, Converter={StaticResource ColorGradientConverter},ConverterParameter=Red, RelativeSource={RelativeSource TemplatedParent}}"
161+
/>
162+
<Slider Grid.Column="0" Grid.Row="1" Foreground="green" Style="{StaticResource Slider_CustomStyle}"
163+
Value="{Binding Path=Green, Converter={StaticResource ByteDoubleConverter}, RelativeSource={RelativeSource TemplatedParent}}"
164+
Background="{Binding Path=Color, Converter={StaticResource ColorGradientConverter},ConverterParameter=Green, RelativeSource={RelativeSource TemplatedParent}}"
165+
/>
166+
<Slider Grid.Column="0" Grid.Row="2" Foreground="blue" Style="{StaticResource Slider_CustomStyle}"
167+
Value="{Binding Path=Blue, Converter={StaticResource ByteDoubleConverter}, RelativeSource={RelativeSource TemplatedParent}}"
168+
Background="{Binding Path=Color, Converter={StaticResource ColorGradientConverter},ConverterParameter=Blue, RelativeSource={RelativeSource TemplatedParent}}"
169+
/>
170+
171+
<Border Grid.Row="0" Grid.RowSpan="3" Grid.Column="2" Width="40" Height="Auto" Margin="5" BorderThickness="1" CornerRadius="5"
172+
Background="{Binding Path=Color, Converter={StaticResource ColorBrushConverter}, RelativeSource={RelativeSource TemplatedParent}}"/>
173+
<Border Grid.Row="0" Grid.RowSpan="3" Grid.Column="2" Width="40" Height="Auto" Margin="5"
174+
BorderThickness="1" CornerRadius="5" Background="{StaticResource BorderBackground}" BorderBrush="{StaticResource BorderBrush}">
175+
176+
177+
</Border>
178+
</Grid>
179+
</Border>
180+
</Border>
181+
</ControlTemplate>
182+
</Setter.Value>
183+
</Setter>
184+
185+
</Style>
186+
187+
</Application.Resources>
188+
</Application>

0 commit comments

Comments
 (0)