Skip to content

Commit 940a77c

Browse files
committed
Update Markdown files
Clean-up and Format with MarkdownLint Convert possible text files to markdown
1 parent b9fe201 commit 940a77c

File tree

3 files changed

+103
-84
lines changed

3 files changed

+103
-84
lines changed
Lines changed: 80 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,120 @@
1+
# Sample Application
2+
13
For the latest info, [visit the wiki article here](https://github.com/windows-toolkit/WindowsCommunityToolkit/wiki/Sample-Development).
24

3-
# How to add new samples
5+
## How to add new samples
46

57
This document describes how to add a new sample page for a new control you want to add to the toolkit.
68

7-
*DropShadowPanel*, *ImageEx*, and *ImageCache* are good examples of most of the features mentioned below.
9+
*`DropShadowPanel`*, *`ImageEx`*, and *`ImageCache`* are good examples of most of the features mentioned below.
810

11+
### 1. Add Sample page and `.bind` template
912

10-
## 1. Add Sample page and .bind template
11-
First you need to create a Xaml page in the folder /SamplePages/YourControl. This will be the logical page used to by the app to navigate to the sample and contains code.
13+
First you need to create a XAML page in the folder `/SamplePages/YourControl`. This will be the logical page used to by the app to navigate to the sample and contains code.
1214

13-
If providing 'live' XAML, a .bind file is loaded and dynamically fed to the XamlReader.Load method to convert into actual controls. This changes a few things about how samples need to be written (detailed below), but allows developers to actually change the sample and see the results live.
15+
If providing 'live' XAML, a `.bind` file is loaded and dynamically fed to the `XamlReader.Load` method to convert into actual controls. This changes a few things about how samples need to be written (detailed below), but allows developers to actually change the sample and see the results live.
1416

1517
This not only gives us a killer sample app, but it also means that all our samples are also self-validating. There can't be a typo in the sample text given in the sample app anymore, as otherwise the sample won't work and should be caught during testing of said sample.
1618

19+
### 2. Binding text
1720

18-
## 2. Binding text
19-
The .bind files are templates which use @[Property Name:Type:DefaultValue:Options] syntax to allow for customized options to be presented to the user in the sample app. The user can play with the values in the property page and see results change instantly. This is accomplished by using {Binding} syntax when on the property page, but switches to the raw value when the developer goes to the XAML page.
21+
The `.bind` files are templates which use `@[Property Name:Type:DefaultValue:Options]` syntax to allow for customized options to be presented to the user in the sample app. The user can play with the values in the property page and see results change instantly. This is accomplished by using {Binding} syntax when on the property page, but switches to the raw value when the developer goes to the XAML page.
2022

2123
This makes it easy for a developer to test out values for a control and then copy the XAML needed for that exact result into their app.
2224

23-
In order to provide a property UI and associated code, you have to define a the .bind XAML file associated with your page.
25+
In order to provide a property UI and associated code, you have to define a `.bind` XAML file associated with your page.
2426
Here is an example:
2527

26-
```xaml
28+
```xml
2729
<Grid>
2830
<Grid.ColumnDefinitions>
2931
<ColumnDefinition Width="48"></ColumnDefinition>
3032
<ColumnDefinition></ColumnDefinition>
3133
</Grid.ColumnDefinitions>
3234
<TextBlock Grid.Column="1"
33-
Text="@[Text:String:Hey!]" Foreground="Black"
34-
FontSize="@[FontSize:Slider:12:10-30]"
35-
VerticalAlignment="@[Vertical Alignment:Enum:VerticalAlignment.Center]">
36-
</TextBlock>
35+
Text="@[Text:String:Hey!]" Foreground="Black"
36+
FontSize="@[FontSize:Slider:12:10-30]"
37+
VerticalAlignment="@[Vertical Alignment:Enum:VerticalAlignment.Center]">
38+
</TextBlock>
3739
</Grid>
3840
```
3941

40-
You can define "interactive" values in this file. The value types can be:
41-
* String: You want the user to provide a text. The string is built like this @[Name:**String**:Default value]
42-
* Slider: You want the user to provide a double value. The string is built like this @[Name:**Slider**:Default value:min-max]
43-
* DoubleSlider: Same as slider but with double values (0.01 precision)
44-
* TimeSpan: You want the user to provide a duration. The string is built like this (all values in milliseconds) @[Name:**TimeSpan**:DefaultValue:min-max]
45-
* Enum: You want the user to provide a enum value. The string is built like this @[Name:**Enum**:EnumType.DefaultValue]
46-
* Brush: You want the user to select a color from a list. The string is built like this @[Name:**Brush**:Black]
47-
* Bool: You want the user to enable or disable a property. The string is built like this @[Name:**Bool**:True]
48-
* Thickness: You want the user to provide a Thickness. The string is built like this @[Name:**Thickness**:0,20,10,0]
42+
You can define “interactive” values in this file. The value types can be:
43+
44+
* `String`: You want the user to provide a text. An equivalent syntax is `@[Name:String:Default Value]`
45+
* `Slider`: You want the user to provide a double value. An equivalent syntax is `@[Name:Slider:DefaultValue:Min-Max]`
46+
* `DoubleSlider`: Same as slider but with double values (0.01 precision)
47+
* `TimeSpan`: You want the user to provide a duration. An equivalent syntax is (all values in milliseconds) `@[Name:TimeSpan:DefaultValue:Min-Max]`
48+
* `Enum`: You want the user to provide an enum value. An equivalent syntax is `@[Name:Enum:EnumType.DefaultValue]`
49+
* `Brush`: You want the user to select a color from a list. An equivalent syntax is `@[Name:Brush:Black]`
50+
* `Bool`: You want the user to enable or disable a property. An equivalent syntax is `@[Name:Bool:True]`
51+
* `Thickness`: You want the user to provide a Thickness. An equivalent syntax is `@[Name:Thickness:0,20,10,0]`
4952

5053
The `Property Name` can also contain spaces, but these will be removed from the property name used for accessing the value in the property bag for any binding/access, see below.
5154

52-
The name and options will be translated **automatically** to the following syntax when your .bind template is being used on the property page:
55+
The name and options will be translated **automatically** to the following syntax when your `.bind` template is being used on the property page:
5356

54-
```xaml
57+
```xml
5558
<Grid Margin="10">
5659
<Grid.ColumnDefinitions>
5760
<ColumnDefinition Width="48"></ColumnDefinition>
5861
<ColumnDefinition></ColumnDefinition>
5962
</Grid.ColumnDefinitions>
6063
<TextBlock Grid.Column="1" Text="{Binding Text.Value, Mode=OneWay}" Foreground="Black"
6164
FontSize="{Binding FontSize.Value, Mode=OneWay}"
62-
VerticalAlignment="{Binding VerticalAlignment.Value, Mode=OneWay}"></TextBlock>
65+
VerticalAlignment="{Binding VerticalAlignment.Value, Mode=OneWay}">
66+
</TextBlock>
6367
</Grid>
6468
```
6569

6670
When the developer switches to the XAML tab, they'll automatically see the selected values instead:
6771

68-
```xaml
72+
```xml
6973
<Grid Margin="10">
7074
<Grid.ColumnDefinitions>
7175
<ColumnDefinition Width="48"></ColumnDefinition>
7276
<ColumnDefinition></ColumnDefinition>
7377
</Grid.ColumnDefinitions>
7478
<TextBlock Grid.Column="1" Text="User Entered Text" Foreground="Black"
7579
FontSize="12"
76-
VerticalAlignment="Left"></TextBlock>
80+
VerticalAlignment="Left">
81+
</TextBlock>
7782
</Grid>
7883
```
7984

8085
You can also reuse a `@[Property Name]` reference by itself again later to use the same binding/value again in the same template. This will automatically get mapped to the right place without the need to specify all the types/options again. Just set those options on your first usage.
8186

82-
If you happen to need a two-way binding for the generated XAML, then add an extra '@' after the property definition in the template:
87+
If you happen to need a two-way binding for the generated XAML, then add an extra '**@**' after the property definition in the template:
8388

84-
```xaml
85-
Value="@[Value:Slider:0:0-180]@"
89+
```xml
90+
<Slider Value="@[Value:Slider:0:0-180]@" />
8691
```
8792

88-
## 3. Have a *'Shallow Copy'* of your example in the sample page
89-
Even though the sample page content is ignored and the dynamic template injected, for the XamlReader to access some classes, a reference to the item is sometimes needed in the hosting app for it to be accessible. (I assume it's an optimization thing.)
93+
### 3. Have a '*Shallow Copy*' of your example in the sample page
94+
95+
Even though the sample page content is ignored and the dynamic template injected, for the `XamlReader` to access some classes, a reference to the item is sometimes needed in the hosting app for it to be accessible. (I assume it's an optimization thing.)
9096

91-
Therefore, for any new control/extension, you should still have a simplified snippet of it contained in the sample page compiled/loaded by the app. You should remove names, events, and properties (unless extensions) from these so the namespace isn't accidentally polluted. If you re-use the same control, you don't have to include it twice.
97+
Therefore, for any new control/extension, you should still have a simplified snippet of it contained in the sample page compiled/loaded by the app. You should remove names, events, and properties (unless extensions) from these, so the namespace isn't accidentally polluted. If you re-use the same control, you don't have to include it twice.
9298

99+
### 4. For Events/Resource Templates: Have your sample page implement the **`IXamlRendererListener`** interface
93100

94-
## 4. For Events/Resource Templates: Have your sample page implement the **IXamlRendererListener** interface
95-
This gets called whenever the template gets parsed (due to loading or user modification). Here you can use the [LogicalTree](https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp.UI/Extensions/Tree/LogicalTree.cs) extensions to grab named controls in the template and register their events. **Check for null first** as the developer may have removed the name from the element.
101+
This gets called whenever the template gets parsed (due to loading or user modification). Here you can use the [`LogicalTree`](https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp.UI/Extensions/FrameworkElement/FrameworkElementExtensions.LogicalTree.cs) extensions to grab named controls in the template and register their events. **Check for null first** as the developer may have removed the name from the element.
96102

97-
```csharp
103+
```cs
98104
var markdownText = control.FindChild("MarkdownText") as MarkdownTextBlock;
99105
if (markdownText != null)
100106
{
101107
markdownText.LinkClicked += MarkdownText_LinkClicked;
102108
}
103109
```
104110

105-
You'll have to register all events and grab **control.Resources** for templates from this method as the regular sample page XAML isn't used and you can't hook in an event from the dynamic XAML, it must be done via code by finding the element here.
111+
You'll have to register all events and grab **`control.Resources`** for templates from this method as the regular sample page XAML isn't used, and you can't hook in an event from the dynamic XAML, it must be done via code by finding the element here.
106112

113+
### 5. For Interactive Buttons: Use **`SampleController.Current.RegisterNewCommand`**
107114

108-
## 5. For Interactive Buttons: Use **SampleController.Current.RegisterNewCommand**
109-
Buttons can be added through this command and are accessible in the main panel so they can be clicked when changing properties or editing XAML. It's important instead of using buttons in your sample (as events can't be directly used, see above) to register these commands.
115+
Buttons can be added through this command and are accessible in the main panel, so they can be clicked when changing properties or editing XAML. It's important instead of using buttons in your sample (as events can't be directly used, see above) to register these commands.
110116

111-
```csharp
117+
```cs
112118
protected override async void OnNavigatedTo(NavigationEventArgs e)
113119
{
114120
base.OnNavigatedTo(e);
@@ -117,26 +123,30 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
117123
{
118124
AddImage(false, true);
119125
});
126+
127+
// ...
128+
}
120129
```
121130

122-
If your command adds content dynamically, try and use a style template in the .bind XAML that the user can modify. Then grab `resources = control.Resources;` in the *OnXamlRendered* event and set the element style from it:
131+
If your command adds content dynamically, try and use a style template in the `.bind` XAML that the user can modify. Then grab `resources = control.Resources;` in the *`OnXamlRendered`* event and set the element style from it:
123132

124-
```csharp
133+
```cs
125134
if (resources?.ContainsKey("ThingStyle") == true)
126135
{
127136
newThing.Style = resources["ThingStyle"] as Style;
128137
}
129138
```
130139

131-
## 6. *Optional:* If you need *extra stuff* around the sample
132-
Now, the sample page content in the app is ignored, but you can override that behavior by adding a `<Grid x:Name="XamlRoot"/>` element to the page. If this element is found, it will serve as the host to the dynamic .bind content instead. In this manner you can have a status/warning message outside of the control of the developer in the XAML sample tab.
140+
### 6. *Optional:* If you need *extra stuff* around the sample
133141

142+
Now, the sample page content in the app is ignored, but you can override that behavior by adding a `<Grid x:Name="XamlRoot"/>` element to the page. If this element is found, it will serve as the host to the dynamic `.bind` content instead. In this manner you can have a status/warning message outside the control of the developer in the XAML sample tab.
134143

135-
# Update Samples.json
136-
After creating your page and the binding text, you just need to reference it in the /SamplePages/samples.json file.
144+
## Update `Samples.json`
145+
146+
After creating your page and the binding text, you just need to reference it in the `/SamplePages/samples.json` file.
137147
Select the category where you want your page to be listed and add the following information:
138148

139-
## Basic Structure
149+
### Basic Structure
140150

141151
```json
142152
[
@@ -148,7 +158,7 @@ Select the category where you want your page to be listed and add the following
148158
"Name": "AdaptiveGridView",
149159
"Type": "AdaptiveGridViewPage",
150160
"About": "The AdaptiveGridView control allows to present information within a Grid View perfectly adjusting the total display available space. It reacts to changes in the layout as well as the content so it can adapt to different form factors automatically. The number and the width of items are calculated based on the screen resolution in order to fully leverage the available screen space. The property ItemsHeight define the items fixed height and the property DesiredWidth sets the minimum width for the elements to add a new column.",
151-
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/TextToolbar",
161+
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls.Core/TextToolbar",
152162
"XamlCodeFile": "AdaptiveGridViewCode.bind",
153163
"DocumentationUrl": "https://raw.githubusercontent.com/windows-toolkit/WindowsCommunityToolkit/master/docs/controls/AdaptiveGridView.md"
154164
}
@@ -157,15 +167,15 @@ Select the category where you want your page to be listed and add the following
157167
]
158168
```
159169

160-
## Thumbnail Images
170+
### Thumbnail Images
161171

162-
> NOTE: If creating a new icon, follow the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)
172+
For creating new icons, please follow the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)
163173

164-
## Restricting Samples to Specific API Sets
174+
### Restricting Samples to Specific API Sets
165175

166176
Some features used by samples aren't available on all the OS versions that the Sample App runs on. In order to make sure a sample is valid for the host OS, add the `ApiCheck` key/value in your JSON definition.
167177

168-
The value is a string which is the fully-qualified typename to check for the presence of. You can also accompany this with the `BadgeUpdateVersionRequred` which uses the string provided to show a short message on the sample information so up level implementors know the minimum version required.
178+
The value is a string which is the fully-qualified type-name to check for the presence of. You can also accompany this with the `BadgeUpdateVersionRequired` which uses the string provided to show a short message on the sample information so up level implementer know the minimum version required.
169179

170180
```json
171181
{
@@ -177,28 +187,31 @@ The value is a string which is the fully-qualified typename to check for the pre
177187
}
178188
```
179189

180-
If the specified type is not found on the system running the sample app the sample will not appear in the sample list.
181-
190+
If the specified type is not found on the system running the sample app, the sample will not appear in the sample list.
182191

183-
### Adding documentation
192+
#### Adding documentation
184193

185-
Every API must be accompanied by Markdown documentation in the [documentation repository](..\contributing.md#docs).
194+
Every API must be accompanied by Markdown doc in the [documentation](https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/master/contributing.md#docs) [repository](https://github.com/MicrosoftDocs/WindowsCommunityToolkitDocs).
186195

187-
Use the DocumentationUrl property to add a link to the raw documentation in *samples.json*. Please follow the following pattern:
196+
Use the `DocumentationUrl` property to add a link to the raw documentation in *`samples.json`*. Please follow the following pattern:
188197

189198
`https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/{branch}/docs/{folder/file.md}`
190199

191-
> NOTE: When building and running the app in release mode, the branch will automatically be changed to **master** before loading.
200+
##### NOTES
192201

193-
> NOTE: The documentation is also packaged with the sample app. If there is no network connection, or the documentation is not yet on GitHub, the sample app will use the packaged version
202+
* When building and running the app in release mode, the branch will automatically be changed to **master** before loading.
203+
* The documentation is also packaged with the sample app. If there is no network connection, or the documentation is not yet on GitHub, the sample app will use the packaged version.
204+
* To test your documentation in the sample app while running in debug mode, the Docs repository will need to be cloned in the same folder as this repository and named **`WindowsCommunityToolkitDocs`**. For
194205

195-
> NOTE: To test your documentation in the sample app while running in debug mode, the docs repository will need to be cloned in the same folder as this repository and named **WindowsCommunityToolkitDocs**. For example, this folder structure works best:
196-
> ```
197-
> repositories
198-
> ├── WindowsCommunityToolkit
199-
> ├── WindowsCommunityToolkitDocs
200-
> ```
206+
Example, this folder structure works best:
207+
208+
```txt
209+
Repos
210+
├── WindowsCommunityToolkit
211+
├── WindowsCommunityToolkitDocs
212+
└── Others
213+
```
201214

202-
### CodeUrl
215+
#### Using `CodeUrl`
203216

204-
The value of CodeUrl is modified when the app is built in release mode. The branch is automatically changed to **master**. This allows you to test the link in debug while pointing to dev.
217+
The value of `CodeUrl` is modified when the app is built in release mode. The branch is automatically changed to **master**. This allows you to test the link in debug while pointing to dev.

Microsoft.Toolkit.Uwp.UI.Controls/Microsoft.Toolkit.Uwp.UI.Controls.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18-
<None Include="$(MSBuildThisFileDirectory)readme.txt" Pack="true" PackagePath="\"/>
18+
<None Include="$(MSBuildThisFileDirectory)ReadMe.md" Pack="true" PackagePath="\"/>
1919
</ItemGroup>
2020

2121
<ItemGroup>

0 commit comments

Comments
 (0)