Skip to content

Commit f608b73

Browse files
Merge pull request #280 from mrlacey/vbdocs
Add and fix VB code samples
2 parents 529f10d + f3b8918 commit f608b73

File tree

4 files changed

+114
-18
lines changed

4 files changed

+114
-18
lines changed

docs/controls/Eyedropper.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,26 @@ The [Eyedropper Control](https://docs.microsoft.com/dotnet/api/microsoft.toolkit
1919
> [Try it in the sample app](uwpct://Controls?sample=Eyedropper)
2020
2121
## Syntax
22-
- Use EyedropperToolButton in xaml.
22+
23+
Use EyedropperToolButton in xaml.
2324

2425
```xaml
2526
<Page ...
2627
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"/>
2728
<controls:EyedropperToolButton />
2829
</Page>
2930
```
30-
- Or use the global Eyedropper in code.
31+
32+
Or use the global Eyedropper in code.
3133

3234
```csharp
3335
var eyedropper = new Eyedropper();
3436
var color = await eyedropper.Open();
3537
```
38+
```vb
39+
Dim eyedropper = New Eyedropper()
40+
Dim color = Await eyedropper.Open()
41+
```
3642

3743
## Sample Output
3844

@@ -88,14 +94,14 @@ var color = await eyedropper.Open();
8894

8995
- Use the global Eyedropper in code.
9096

91-
```csharp
92-
var eyedropper = new Eyedropper();
93-
var color = await eyedropper.Open();
94-
```
95-
```vb
96-
Dim eyedropper = New Eyedropper()
97-
Dim color = Await eyedropper.Open()
98-
```
97+
```csharp
98+
var eyedropper = new Eyedropper();
99+
var color = await eyedropper.Open();
100+
```
101+
```vb
102+
Dim eyedropper = New Eyedropper()
103+
Dim color = Await eyedropper.Open()
104+
```
99105

100106
## Sample Project
101107

@@ -114,4 +120,4 @@ var color = await eyedropper.Open();
114120

115121
## API
116122

117-
* [Eyedropper source code](https://github.com/Microsoft/WindowsCommunityToolkit//tree/master/Microsoft.Toolkit.Uwp.UI.Controls/Eyedropper)
123+
* [Eyedropper source code](https://github.com/Microsoft/WindowsCommunityToolkit//tree/master/Microsoft.Toolkit.Uwp.UI.Controls/Eyedropper)

docs/controls/ImageCropper.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ The [ImageCropper Control](https://docs.microsoft.com/dotnet/api/microsoft.toolk
3030

3131
## Properties
3232

33-
3433
| Property | Type | Description |
3534
| --------------------- | --------------- | ------------------------------------------------------------ |
3635
| MinCroppedPixelLength | double | Gets or sets the minimum cropped length(in pixel). |
@@ -44,7 +43,6 @@ The [ImageCropper Control](https://docs.microsoft.com/dotnet/api/microsoft.toolk
4443
| SecondaryThumbStyle | Style | Gets or sets a value for the style to use for the secondary thumbs of the ImageCropper. |
4544
| ThumbPlacement | ThumbPlacement | Gets or sets a value for thumb placement. |
4645

47-
4846
## Methods
4947

5048
| Methods | Return Type | Description |
@@ -54,10 +52,10 @@ The [ImageCropper Control](https://docs.microsoft.com/dotnet/api/microsoft.toolk
5452
| Reset() | void | Reset the cropped area. |
5553
| TrySetCroppedRegion(Rect rect) | bool | Tries to set a new value for the cropped region, returns true if it succeeded, false if the region is invalid |
5654

57-
5855
## Examples
5956

6057
### Use ImageCropper
58+
6159
You can set the cropped image source by using the `LoadImageFromFile(StorageFile)` method or setting the `Source` property.
6260

6361
```csharp
@@ -73,7 +71,7 @@ using (var fileStream = await someFile.OpenAsync(FileAccessMode.ReadWrite, Stora
7371
await _imageCropper.SaveAsync(fileStream, BitmapFileFormat.Png);
7472
}
7573
```
76-
``vb
74+
```vb
7775
' Load an image.
7876
Await ImageCropper.LoadImageFromFile(file)
7977

@@ -92,7 +90,7 @@ You can set `CropShape` property to use the circular ImageCropper.
9290
```csharp
9391
ImageCropper.CropShape = CropShape.Circular;
9492
```
95-
``vb
93+
```vb
9694
ImageCropper.CropShape = CropShape.Circular
9795
```
9896

@@ -102,7 +100,7 @@ You can set `AspectRatio` property to change the aspect ratio of the cropped ima
102100
```csharp
103101
ImageCropper.AspectRatio = 16d / 9d;
104102
```
105-
``vb
103+
```vb
106104
ImageCropper.AspectRatio = 16R / 9R
107105
```
108106

@@ -111,7 +109,7 @@ Or you can crop image without aspect ratio.
111109
```csharp
112110
ImageCropper.AspectRatio = null;
113111
```
114-
``vb
112+
```vb
115113
ImageCropper.AspectRatio = Nothing
116114
```
117115

docs/controls/wpf-winforms/MapControl.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ title: MapControl for Windows Forms and WPF
33
author: mcleanbyron
44
description: This control is a wrapper to enable use of the UWP MapControl class in Windows Forms or WPF.
55
keywords: windows 10, uwp, windows community toolkit, uwp community toolkit, uwp toolkit, MapControl, Windows Forms, WPF
6+
dev_langs:
7+
- csharp
8+
- vb
69
---
710

811
# MapControl for Windows Forms and WPF
@@ -56,6 +59,16 @@ private async void MapControl_Loaded(object sender, RoutedEventArgs e)
5659
await (sender as MapControl).TrySetViewAsync(cityCenter, 12);
5760
}
5861
```
62+
```vb
63+
Private Async Sub MapControl_Loaded(sender As Object, e As RoutedEventArgs)
64+
Dim cityPosition As BasicGeoposition = New BasicGeoposition() With {
65+
.Latitude = 47.604,
66+
.Longitude = -122.329
67+
}
68+
Dim cityCenter = New Geopoint(cityPosition)
69+
Await (TryCast(sender, MapControl)).TrySetViewAsync(cityCenter, 12)
70+
End Sub
71+
```
5972

6073
## Properties
6174

docs/controls/wpf-winforms/WindowsXamlHost.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ title: WindowsXAMLHost control
33
author: mcleanbyron
44
description: This guide helps you add UWP XAML controls to your WPF.
55
keywords: windows 10, uwp, windows community toolkit, uwp community toolkit, uwp toolkit, host controls, xaml islands, WPF, Windows Forms
6+
dev_langs:
7+
- csharp
8+
- vb
69
---
710

811
# WindowsXamlHost control for Windows Forms and WPF
@@ -97,6 +100,18 @@ Before getting started, follow these instructions to install the necessary NuGet
97100
MessageBox.Show("My UWP button works");
98101
}
99102
```
103+
```vb
104+
Private Sub MyWindowsXAMLHost_ChildChanged(sender As Object, e As EventArgs)
105+
Dim windowsXamlHost As WindowsXamlHost = CType(sender, WindowsXamlHost)
106+
Dim button As Windows.UI.Xaml.Controls.Button = CType(windowsXamlHost.Child, Windows.UI.Xaml.Controls.Button)
107+
button.Content = "My UWP button"
108+
AddHandler button.Click, AddressOf Button_Click
109+
End Sub
110+
111+
Private Sub Button_Click(sender As Object, e As Windows.UI.Xaml.RoutedEventArgs)
112+
MessageBox.Show("My UWP button works")
113+
End Sub
114+
```
100115

101116
### Create and host UWP controls dynamically at run time
102117

@@ -139,6 +154,36 @@ private void MyButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
139154
MessageBox.Show("This is a UWP button.");
140155
}
141156
```
157+
```vb
158+
Private Sub UseHelperMethod()
159+
Dim myHostControl As Microsoft.Toolkit.Wpf.UI.XamlHost.WindowsXamlHost = New Microsoft.Toolkit.Wpf.UI.XamlHost.WindowsXamlHost()
160+
161+
' Use helper method to create a UWP control instance.
162+
Dim myButton As Windows.UI.Xaml.Controls.Button = TryCast(Microsoft.Toolkit.Win32.UI.XamlHost.UWPTypeFactory.CreateXamlContentByType("Windows.UI.Xaml.Controls.Button"), Windows.UI.Xaml.Controls.Button)
163+
164+
' Initialize UWP control.
165+
myButton.Name = "button1"
166+
myButton.Width = 75
167+
myButton.Height = 40
168+
myButton.TabIndex = 0
169+
myButton.Content = "button1"
170+
AddHandler myButton.Click, AddressOf MyButton_Click
171+
172+
' initialize the Windows XAML host control.
173+
myHostControl.Name = "myWindowsXamlHostControl"
174+
175+
' Associate the Windows XAML host control with the UWP control.
176+
' For Windows Forms applications, you might use this.Controls.Add(myHostControl);
177+
myHostControl.Child = myButton
178+
179+
' Make the UWP control appear in the UI.
180+
Me.MyStackPanel.Children.Add(myHostControl)
181+
End Sub
182+
183+
Private Sub MyButton_Click(sender As Object, e As Windows.UI.Xaml.RoutedEventArgs)
184+
MessageBox.Show("My UWP button works")
185+
End Sub
186+
```
142187

143188
### Initialize UWP controls first, and then assign them to WindowsXamlHost controls
144189

@@ -185,6 +230,40 @@ private void MyButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
185230
MessageBox.Show("This is a UWP button.");
186231
}
187232
```
233+
```vb
234+
Private Sub CreateUWPControlsFirst()
235+
' Initialize the UWP hosting environment.
236+
Windows.UI.Xaml.Hosting.WindowsXamlManager.InitializeForCurrentThread()
237+
238+
' Create a UWP control.
239+
Dim myButton As Windows.UI.Xaml.Controls.Button = New Windows.UI.Xaml.Controls.Button()
240+
241+
' Initialize UWP control.
242+
myButton.Name = "button1"
243+
myButton.Width = 75
244+
myButton.Height = 40
245+
myButton.TabIndex = 0
246+
myButton.Content = "button1"
247+
AddHandler myButton.Click, AddressOf MyButton_Click
248+
249+
' Create a Windows XAML host control.
250+
Dim myHostControl As Microsoft.Toolkit.Wpf.UI.XamlHost.WindowsXamlHost = New Microsoft.Toolkit.Wpf.UI.XamlHost.WindowsXamlHost()
251+
252+
' initialize the Windows XAML host control.
253+
myHostControl.Name = "myWindowsXamlHostControl"
254+
255+
' Associate the Windows XAML host control with the UWP control.
256+
myHostControl.Child = myButton
257+
258+
' Make the UWP control appear in the UI.
259+
' For Windows Forms applications, you might use this.Controls.Add(myHostControl);
260+
Me.MyStackPanel.Children.Add(myHostControl)
261+
End Sub
262+
263+
Private Sub MyButton_Click(sender As Object, e As Windows.UI.Xaml.RoutedEventArgs)
264+
MessageBox.Show("My UWP button works")
265+
End Sub
266+
```
188267

189268
## Sample Project
190269

0 commit comments

Comments
 (0)