Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FeatureForm WPF: Tooltip shows even when empty #560

3 changes: 3 additions & 0 deletions src/Toolkit/Toolkit.Maui/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
[assembly: System.Runtime.Versioning.SupportedOSPlatform("ios14.0")]
[assembly: System.Runtime.Versioning.SupportedOSPlatform("maccatalyst14.0")]
#endif

[assembly: Microsoft.Maui.Controls.XmlnsPrefix("http://schemas.esri.com/arcgis/runtime/2013", "esri")]
[assembly: XmlnsDefinition("http://schemas.esri.com/arcgis/runtime/2013", "Esri.ArcGISRuntime.Toolkit.Maui")]
1 change: 1 addition & 0 deletions src/Toolkit/Toolkit.WPF/Themes/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<ResourceDictionary Source="/Esri.ArcGISRuntime.Toolkit.WPF;component/UI/Controls/TableOfContents/TableOfContents.Theme.xaml" />
<ResourceDictionary Source="/Esri.ArcGISRuntime.Toolkit.WPF;component/UI/Controls/TimeSlider/TimeSlider.Theme.xaml" />
<ResourceDictionary Source="/Esri.ArcGISRuntime.Toolkit.WPF;component/UI/Controls/PopupViewer/PopupViewer.Theme.xaml" />
<ResourceDictionary Source="/Esri.ArcGISRuntime.Toolkit.WPF;component/UI/Controls/FeatureForm/FeatureFormView.Theme.xaml" />
</ResourceDictionary.MergedDictionaries>


Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Toolkit/Toolkit.WPF/VisualStudioToolsManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Item Type="Esri.ArcGISRuntime.Toolkit.UI.Controls.BasemapGallery" />
<Item Type="Esri.ArcGISRuntime.Toolkit.UI.Controls.BookmarksView" />
<Item Type="Esri.ArcGISRuntime.Toolkit.UI.Controls.FeatureDataField" />
<Item Type="Esri.ArcGISRuntime.Toolkit.UI.Controls.FeatureFormView" />
<Item Type="Esri.ArcGISRuntime.Toolkit.UI.Controls.Legend" />
<Item Type="Esri.ArcGISRuntime.Toolkit.UI.Controls.MeasureToolbar" />
<Item Type="Esri.ArcGISRuntime.Toolkit.UI.Controls.OverviewMap" />
Expand Down
129 changes: 129 additions & 0 deletions src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#if WPF
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping.FeatureForms;
using System.ComponentModel;

namespace Esri.ArcGISRuntime.Toolkit.Primitives
{
/// <summary>
/// Checkbox switch for the <see cref="ComboBoxFormInput"/>.
/// </summary>
[TemplatePart(Name ="Selector", Type = typeof(System.Windows.Controls.Primitives.Selector))]
public class ComboBoxFormInputView : Control
{
private System.Windows.Controls.Primitives.Selector? _selector;

/// <summary>
/// Initializes an instance of the <see cref="ComboBoxFormInputView"/> class.
/// </summary>
public ComboBoxFormInputView()
{
DefaultStyleKey = typeof(ComboBoxFormInputView);
}

/// <inheritdoc />
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
if (_selector != null)
{
_selector.SelectionChanged -= Selector_SelectionChanged;
}
_selector = GetTemplateChild("Selector") as System.Windows.Controls.Primitives.Selector;
if(_selector != null)
{
_selector.SelectionChanged += Selector_SelectionChanged;
}
UpdateItems();
}

/// <summary>
/// Gets or sets the FieldFormElement.
/// </summary>
public FieldFormElement? Element
{
get { return (FieldFormElement)GetValue(ElementProperty); }
set { SetValue(ElementProperty, value); }
}

/// <summary>
/// Identifies the <see cref="Element"/> dependency property.
/// </summary>
public static readonly DependencyProperty ElementProperty =
DependencyProperty.Register(nameof(Element), typeof(FieldFormElement), typeof(ComboBoxFormInputView), new PropertyMetadata(null, (s, e) => ((ComboBoxFormInputView)s).OnElementPropertyChanged(e.OldValue as FieldFormElement, e.NewValue as FieldFormElement)));

private void OnElementPropertyChanged(FieldFormElement? oldValue, FieldFormElement? newValue)
{
if (oldValue is INotifyPropertyChanged inpcOld)
{
inpcOld.PropertyChanged += FeatureFormTextInputView_PropertyChanged; //TODO: Weak
}
if (newValue is INotifyPropertyChanged inpcNew)
{
inpcNew.PropertyChanged += FeatureFormTextInputView_PropertyChanged;
}
UpdateItems();
}

private void FeatureFormTextInputView_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(FieldFormElement.Value))
{
UpdateSelection();
}
}

private void UpdateItems()
{
if (_selector is not null)
{
if (Element?.Input is ComboBoxFormInput input)
{
_selector.DisplayMemberPath = nameof(CodedValue.Name);
List<object> items = new List<object>();
if (input.NoValueOption == FormInputNoValueOption.Show)
{
items.Add(new ComboBoxNullValue() { Name = input.NoValueLabel });
}
items.AddRange(input.CodedValues);
_selector.ItemsSource = items;
UpdateSelection();
}
else
{
_selector.SelectedItem = null;
_selector.ItemsSource = null;
}
}
}

private void UpdateSelection()
{
if (_selector is not null)
{
if (Element?.Input is ComboBoxFormInput input)
{
var selection = input.CodedValues.Where(a => object.Equals(a.Code, Element?.Value)).FirstOrDefault();
if (selection is null && input.NoValueOption == FormInputNoValueOption.Show)
_selector.SelectedIndex = 0;
else
_selector.SelectedItem = selection;
}
}
}

private void Selector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var value = (_selector?.SelectedItem as CodedValue)?.Code;
Element?.UpdateValue(value);
}

private class ComboBoxNullValue
{
public object? Code { get; set; }
public string? Name { get; set; }
public override string ToString() => Name!;
}
}
}
#endif
114 changes: 114 additions & 0 deletions src/Toolkit/Toolkit/UI/Controls/FeatureForm/DatePickerFormInputView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#if WPF
using Esri.ArcGISRuntime.Mapping.FeatureForms;

namespace Esri.ArcGISRuntime.Toolkit.Primitives
{
/// <summary>
/// Picker for the <see cref="DateTimePickerFormInput"/>.
/// </summary>
[TemplatePart(Name = "DatePicker", Type = typeof(DatePicker))]
public class DateTimePickerFormInputView : Control
{
private DatePicker? _datePicker;
private TimePicker? _timePicker;

/// <summary>
/// Initializes an instance of the <see cref="DateTimePickerFormInputView"/> class.
/// </summary>
public DateTimePickerFormInputView()
{
DefaultStyleKey = typeof(DateTimePickerFormInputView);
}

/// <inheritdoc />
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_datePicker = GetTemplateChild("DatePicker") as DatePicker;
_timePicker = GetTemplateChild("TimePicker") as TimePicker;
if (_datePicker != null)
{
_datePicker.SelectedDateChanged += DatePicker_SelectedDateChanged;
}
if (_timePicker != null)
{
_timePicker.TimeChanged += TimePicker_TimeChanged;
}
ConfigurePickers();
}

private void TimePicker_TimeChanged(object? sender, EventArgs e) => UpdateValue();

private void DatePicker_SelectedDateChanged(object? sender, SelectionChangedEventArgs e) => UpdateValue();

private void UpdateValue()
{
if (Element?.Input is DateTimePickerFormInput input && _datePicker != null)
{
var date = _datePicker.SelectedDate;
if(date.HasValue && input.IncludeTime && _timePicker != null && _timePicker.Time.HasValue)
{
date = date.Value.Subtract(date.Value.TimeOfDay).Add(_timePicker.Time.Value);
}
if (!object.Equals(Element?.Value, date))
Element?.UpdateValue(date);
}
}

/// <summary>
/// Gets or sets the FieldFormElement.
/// </summary>
public FieldFormElement? Element
{
get { return (FieldFormElement)GetValue(ElementProperty); }
set { SetValue(ElementProperty, value); }
}

/// <summary>
/// Identifies the <see cref="Element"/> dependency property.
/// </summary>
public static readonly DependencyProperty ElementProperty =
DependencyProperty.Register(nameof(Element), typeof(FieldFormElement), typeof(DateTimePickerFormInputView), new PropertyMetadata(null, (s, e) => ((DateTimePickerFormInputView)s).OnElementPropertyChanged(e.OldValue as FieldFormElement, e.NewValue as FieldFormElement)));

private void OnElementPropertyChanged(FieldFormElement? oldValue, FieldFormElement? newValue)
{
if (newValue is not null)
{
((System.ComponentModel.INotifyPropertyChanged)newValue).PropertyChanged += Element_PropertyChanged;
}
}

private void Element_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(FieldFormElement.Value))
{
ConfigurePickers();
}
}

private bool _rentrancyFlag;

private void ConfigurePickers()
{
if (_rentrancyFlag) return;
_rentrancyFlag = true;
DateTime? selectedDate = (DateTime?)Element?.Value;
if (Element?.Input is DateTimePickerFormInput input)
{
if (_datePicker is not null)
{
_datePicker.SelectedDate = selectedDate;
_datePicker.DisplayDateStart = input.Min.HasValue ? input.Min.Value.Date : null;
_datePicker.DisplayDateEnd = input.Max.HasValue ? input.Max.Value.Date : null;
}
if (_timePicker != null)
{
_timePicker.Visibility = input.IncludeTime ? Visibility.Visible : Visibility.Collapsed;
_timePicker.Time = selectedDate.HasValue ? selectedDate.Value.TimeOfDay : null;
}
}
_rentrancyFlag = false;
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// /*******************************************************************************
// * Copyright 2012-2018 Esri
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// ******************************************************************************/

#if MAUI
using Microsoft.Maui.Controls.Internals;
using Esri.ArcGISRuntime.Mapping.FeatureForms;
using Esri.ArcGISRuntime.Toolkit.Maui.Primitives;
using System.Diagnostics.CodeAnalysis;

namespace Esri.ArcGISRuntime.Toolkit.Maui
{
public partial class FeatureFormView : TemplatedView
{
private static readonly ControlTemplate DefaultControlTemplate;

/// <summary>
/// Template name of the <see cref="IBindableLayout"/> items layout view.
/// </summary>
public const string ItemsViewName = "ItemsView";

/// <summary>
/// Template name of the form's content's <see cref="ScrollView"/>.
/// </summary>
public const string FeatureFormContentScrollViewerName = "FeatureFormContentScrollViewer";

static FeatureFormView()
{
DefaultControlTemplate = new ControlTemplate(BuildDefaultTemplate);
}

[DynamicDependency(nameof(Esri.ArcGISRuntime.Mapping.FeatureForms.FeatureForm.Title), "Esri.ArcGISRuntime.Mapping.FeatureForms.FeatureForm", "Esri.ArcGISRuntime")]
[DynamicDependency(nameof(Esri.ArcGISRuntime.Mapping.FeatureForms.FeatureForm.Elements), "Esri.ArcGISRuntime.Mapping.FeatureForms.FeatureForm", "Esri.ArcGISRuntime")]
private static object BuildDefaultTemplate()
{
throw new NotImplementedException("TODO");
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// /*******************************************************************************
// * Copyright 2012-2018 Esri
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// ******************************************************************************/

#if WPF
using Esri.ArcGISRuntime.Mapping.FeatureForms;
using Esri.ArcGISRuntime.Toolkit.Internal;
using System.ComponentModel;
using System.Diagnostics;

namespace Esri.ArcGISRuntime.Toolkit.UI.Controls
{
[TemplatePart(Name = FeatureFormContentScrollViewerName, Type = typeof(ScrollViewer))]
[TemplatePart(Name = ItemsViewName, Type = typeof(ItemsControl))]
public partial class FeatureFormView : Control
{
private const string ItemsViewName = "ItemsView";
private const string FeatureFormContentScrollViewerName = "FeatureFormContentScrollViewer";

}
}
#endif
Loading
Loading