Skip to content

Commit 2211e75

Browse files
authored
MAUI WinUI: Fix ItemsSource issues in several samples. (#1177)
1 parent 417e222 commit 2211e75

File tree

6 files changed

+33
-71
lines changed

6 files changed

+33
-71
lines changed

src/MAUI/Maui.Samples/Samples/Geometry/SpatialOperations/SpatialOperations.xaml.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public SpatialOperations()
4545

4646
private void Initialize()
4747
{
48+
// Fill the combo box with some spatial operations to run on the polygon graphics.
49+
SpatialOperationComboBox.ItemsSource = new string[] { "Difference", "Intersection", "Symmetric difference", "Union" };
50+
4851
// Create the map with a gray canvas basemap and an initial location centered on London, UK.
4952
Map myMap = new Map(BasemapStyle.ArcGISLightGray);
5053
myMap.InitialViewpoint = new Viewpoint(51.5017, -0.12714, 20000);
@@ -54,12 +57,6 @@ private void Initialize()
5457

5558
// Create and add two overlapping polygon graphics to operate on.
5659
CreatePolygonsOverlay();
57-
58-
// Fill the combo box with some spatial operations to run on the polygon graphics.
59-
SpatialOperationComboBox.Items.Add("Difference");
60-
SpatialOperationComboBox.Items.Add("Intersection");
61-
SpatialOperationComboBox.Items.Add("Symmetric difference");
62-
SpatialOperationComboBox.Items.Add("Union");
6360
}
6461

6562
// Handle the spatial operation selection by performing the operation and showing the result polygon.

src/MAUI/Maui.Samples/Samples/Layers/RasterHillshade/RasterHillshade.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ private async Task Initialize()
8383
// Add slope type values to the dictionary and picker
8484
foreach (object slope in Enum.GetValues(typeof(SlopeType)))
8585
{
86-
_slopeTypeValues.Add(slope.ToString(), (SlopeType)slope);
87-
SlopeTypePicker.Items.Add(slope.ToString());
86+
_slopeTypeValues.Add(Enum.GetName((SlopeType)slope), (SlopeType)slope);
8887
}
88+
SlopeTypePicker.ItemsSource = Enum.GetNames(typeof(SlopeType));
8989

9090
// Select the "Scaled" slope type enum
9191
SlopeTypePicker.SelectedIndex = 2;

src/MAUI/Maui.Samples/Samples/Layers/RasterRgbRenderer/RasterRgbRenderer.xaml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<esriUI:MapView x:Name="MyMapView" Style="{DynamicResource EsriSampleGeoView}" />
88
<Border Style="{DynamicResource EsriSampleControlPanel}">
99
<Grid Grid.Row="1"
10+
Padding="5"
1011
ColumnDefinitions="*,*"
1112
ColumnSpacing="5"
1213
HorizontalOptions="Center"
@@ -95,51 +96,51 @@
9596
Grid.Row="1"
9697
Grid.Column="0"
9798
Grid.ColumnSpan="4"
98-
ColumnDefinitions="*, 4*"
99+
ColumnDefinitions="auto,175"
99100
IsVisible="False"
100101
RowDefinitions="auto,auto">
101102
<Label Grid.Row="0"
102103
Grid.Column="0"
103-
HorizontalOptions="Center"
104-
Text="Min %: "
104+
HorizontalOptions="Start"
105+
Text="Min %"
105106
VerticalOptions="CenterAndExpand" />
106107
<Slider x:Name="MinimumValueSlider"
107108
Grid.Row="0"
108109
Grid.Column="1"
110+
Margin="5,0"
109111
Maximum="100"
110112
Minimum="0"
111-
VerticalOptions="CenterAndExpand" />
113+
VerticalOptions="Center" />
112114
<Label Grid.Row="1"
113115
Grid.Column="0"
114-
HorizontalOptions="Center"
115-
Text="Max %: "
116+
HorizontalOptions="Start"
117+
Text="Max %"
116118
VerticalOptions="CenterAndExpand" />
117119
<Slider x:Name="MaximumValueSlider"
118120
Grid.Row="1"
119121
Grid.Column="1"
122+
Margin="5,0"
120123
Maximum="100"
121124
Minimum="0"
122-
VerticalOptions="CenterAndExpand" />
125+
VerticalOptions="Center" />
123126
</Grid>
124127
<Grid x:Name="StdDeviationParametersGrid"
125128
Grid.Row="1"
126129
Grid.Column="0"
127130
Grid.ColumnSpan="4"
128-
ColumnDefinitions="120,100"
129-
IsVisible="False"
130-
RowDefinitions="20,*">
131-
<Label Grid.Row="1"
132-
Grid.Column="0"
131+
ColumnDefinitions="auto,auto"
132+
IsVisible="False">
133+
<Label Grid.Column="0"
133134
HorizontalOptions="Center"
134-
Text="Factor: "
135+
Text="Factor:"
135136
VerticalOptions="CenterAndExpand" />
136137
<Picker x:Name="StdDeviationFactorComboBox"
137-
Grid.Row="1"
138138
Grid.Column="1"
139139
Grid.ColumnSpan="2"
140+
Margin="5,0"
140141
HorizontalOptions="Start"
141142
VerticalOptions="CenterAndExpand"
142-
WidthRequest="60" />
143+
WidthRequest="100" />
143144
</Grid>
144145
<Button x:Name="ApplyRgbRendererButton"
145146
Grid.Row="2"

src/MAUI/Maui.Samples/Samples/Layers/RasterRgbRenderer/RasterRgbRenderer.xaml.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public RasterRgbRenderer()
3636

3737
private async Task Initialize()
3838
{
39+
// Add available stretch types to the combo box.
40+
StretchTypeComboBox.ItemsSource = new string[] { "Min Max", "Percent Clip", "Standard Deviation" };
41+
3942
// Create a map with a streets basemap.
4043
Map map = new Map(BasemapStyle.ArcGISStreets);
4144

@@ -66,11 +69,6 @@ private async Task Initialize()
6669
// Add the map to the map view.
6770
MyMapView.Map = map;
6871

69-
// Add available stretch types to the combo box.
70-
StretchTypeComboBox.Items.Add("Min Max");
71-
StretchTypeComboBox.Items.Add("Percent Clip");
72-
StretchTypeComboBox.Items.Add("Standard Deviation");
73-
7472
// Select "Min Max" as the stretch type.
7573
StretchTypeComboBox.SelectedIndex = 0;
7674

src/MAUI/Maui.Samples/Samples/Map/ManageBookmarks/ManageBookmarks.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<Label HorizontalTextAlignment="Center"
1313
Text="Bookmark:"
1414
VerticalTextAlignment="Center" />
15-
<Picker x:Name="bookmarkPicker"
15+
<Picker x:Name="BookmarkPicker"
16+
ItemDisplayBinding="{Binding Path=Name}"
1617
SelectedIndexChanged="BookmarkPicker_SelectedIndexChanged"
1718
VerticalOptions="CenterAndExpand"
1819
WidthRequest="200" />

src/MAUI/Maui.Samples/Samples/Map/ManageBookmarks/ManageBookmarks.xaml.cs

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ public ManageBookmarks()
2828
private void Initialize()
2929
{
3030
// Create new map with a base map
31-
Map myMap = new Map(BasemapStyle.ArcGISImagery);
31+
MyMapView.Map = new Map(BasemapStyle.ArcGISImagery);
3232

33-
// Add the map to the mapview
34-
MyMapView.Map = myMap;
33+
BookmarkPicker.ItemsSource = MyMapView.Map.Bookmarks;
3534

3635
// Create a set of predefined bookmarks; each one follows the pattern of:
3736
// ~ Initialize a viewpoint pointing to a latitude longitude
@@ -49,7 +48,6 @@ private void Initialize()
4948
Viewpoint = myViewpoint1
5049
};
5150
MyMapView.Map.Bookmarks.Add(myBookmark1);
52-
bookmarkPicker.Items.Add(myBookmark1.Name);
5351

5452
// Bookmark-2
5553
Viewpoint myViewpoint2 = new Viewpoint(-39.299987, 174.060858, 600000);
@@ -59,7 +57,6 @@ private void Initialize()
5957
Viewpoint = myViewpoint2
6058
};
6159
MyMapView.Map.Bookmarks.Add(myBookmark2);
62-
bookmarkPicker.Items.Add(myBookmark2.Name);
6360

6461
// Bookmark-3
6562
Viewpoint myViewpoint3 = new Viewpoint(-33.867886, -63.985, 40000);
@@ -69,7 +66,6 @@ private void Initialize()
6966
Viewpoint = myViewpoint3
7067
};
7168
MyMapView.Map.Bookmarks.Add(myBookmark3);
72-
bookmarkPicker.Items.Add(myBookmark3.Name);
7369

7470
// Bookmark-4
7571
Viewpoint myViewpoint4 = new Viewpoint(44.525049, -110.83819, 6000);
@@ -79,44 +75,20 @@ private void Initialize()
7975
Viewpoint = myViewpoint4
8076
};
8177
MyMapView.Map.Bookmarks.Add(myBookmark4);
82-
bookmarkPicker.Items.Add(myBookmark4.Name);
8378

8479
// Set the initial combo box selection to the last bookmark added
85-
bookmarkPicker.SelectedIndex = 3;
86-
87-
// Zoom to the last bookmark
88-
myMap.InitialViewpoint = myMap.Bookmarks.Last().Viewpoint;
80+
BookmarkPicker.SelectedIndex = 0;
8981
}
9082

9183
private void BookmarkPicker_SelectedIndexChanged(object sender, EventArgs e)
9284
{
93-
// Get the selected bookmarks name
94-
string selectedBookmarkName = bookmarkPicker.Items[bookmarkPicker.SelectedIndex];
95-
96-
// Get the collection of bookmarks in the map
97-
BookmarkCollection myBookmarkCollection = MyMapView.Map.Bookmarks;
98-
99-
// Loop through each bookmark
100-
foreach (Bookmark myBookmark in myBookmarkCollection)
101-
{
102-
// Get the bookmarks name
103-
string theBookmarkName = myBookmark.Name;
104-
105-
// If the selected bookmarks name matches one in the bookmark collection
106-
// set that to be the maps viewpoint
107-
if (theBookmarkName == selectedBookmarkName.ToString())
108-
{
109-
MyMapView.SetViewpoint(myBookmark.Viewpoint);
110-
}
85+
// Verify that the selected item is a bookmark.
86+
if(BookmarkPicker.SelectedItem is Bookmark bookmark)
87+
{
88+
MyMapView.SetViewpoint(bookmark.Viewpoint);
11189
}
11290
}
11391

114-
// Member (aka. global) variables for the dynamically created page allowing
115-
// the user to add additional bookmarks
116-
public Entry myEntryBookmarkName;
117-
118-
public ContentPage bookmarkAddPage;
119-
12092
private async void ButtonAddBookmark_Clicked(object sender, EventArgs e)
12193
{
12294
try
@@ -144,13 +116,6 @@ private async void ButtonAddBookmark_Clicked(object sender, EventArgs e)
144116

145117
// Add the bookmark to bookmark collection of the map
146118
MyMapView.Map.Bookmarks.Add(myBookmark);
147-
148-
// Add the bookmark name to the list of choices in the picker
149-
bookmarkPicker.Items.Add(name);
150-
151-
// Close the user interaction page to add a bookmark
152-
Navigation.RemovePage(bookmarkAddPage);
153-
bookmarkAddPage = null;
154119
}
155120
catch (Exception)
156121
{

0 commit comments

Comments
 (0)