Microsoft.Toolkit.Win32 icon indicating copy to clipboard operation
Microsoft.Toolkit.Win32 copied to clipboard

Data binding with "Center" property of map control does not work

Open lafe opened this issue 4 years ago • 4 comments

Describe the bug

The Center property of the MapControl does not bind to a view model and also does not react to changed properties.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Create a new .NET Core 3.1 WPF project and setup MVVM data binding.

  2. The following grid is used (data binding setup omitted):

    <Window x:Class="..."
         ...
         xmlns:mappedControls="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls"
         ....>
     ...
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="*"/>
             <RowDefinition Height="Auto"/>
             <RowDefinition Height="Auto"/>
         </Grid.RowDefinitions>
         <mappedControls:MapControl 
             x:Name="MainMap"
             Grid.Row="0"
             MapServiceToken="{Binding Configuration.MapServiceToken}"
             ZoomLevel="12"
             Center="{Binding CurrentPosition, Mode=OneWay}" />
         <TextBox Grid.Row="1" Text="{Binding Latitude}"/>
         <TextBox Grid.Row="2" Text="{Binding Longitude}"/>
     </Grid>
    
  3. The relevant properties of the View Model has the following properties (excerpt):

         private double _latitude;
         public double Latitude
         {
             get => _latitude;
             set
             {
                 if (value.Equals(_latitude)) return;
                 _latitude = value;
                 OnPropertyChanged();
                 OnPropertyChanged(nameof(CurrentPosition));
             }
         }
    
         private double _longitude;
         public double Longitude
         {
             get => _longitude;
             set
             {
                 if (value.Equals(_longitude)) return;
                 _longitude = value;
                 OnPropertyChanged();
                 OnPropertyChanged(nameof(CurrentPosition));
             }
         }
    
         public Geopoint CurrentPosition
         {
             get
             {
                 return new Geopoint(new BasicGeoposition()
                 {
                     Latitude = Latitude,
                     Longitude = Longitude
                 });
             }
         }
    
  4. When the application starts, the text boxes are filled correctly and breakpoints indicate that data binding works between text boxes and dedicated properties. The CurrentPosition property is retrieved only once and is not retrieved when the PropertyChanged event is fired for it (indicating that databinding does not work).

Expected behavior

The Center property of the map control is correctly bound to the CurrentPosition property and is retrieved when the base properties are updated.

Environment

NuGet Package(s): 

Package Version(s): 

Project .NET Version:
- [ ] .NET Framework (version: )
- [ ] .NET Core 3
- [ ] .NET Core 3.1 Preview (version: )
- [X] .NET Core 3.1 (version: 3.1.302)

Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [X] November 2019 Update (18363)
- [ ] Insider Build (build number: )

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [x] November 2019 Update (18363)
- [ ] Insider Build (xxxxx)

Device form factor:
- [X] Desktop
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [ ] 2017 (version: )
- [X] 2019 (version: 16.6.5) 
- [ ] 2019 Preview (version: )

Additional context

I have searched the issue extensively but did not find any examples on how to use the map control with MVVM. Furthermore, I tested multiple binding behaviors which was also not successful.

lafe avatar Aug 29 '20 09:08 lafe

Hello lafe, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

ghost avatar Aug 29 '20 09:08 ghost

Hi @lafe, can you send a repo please?

marb2000 avatar Sep 01 '20 20:09 marb2000

@marb2000 Will do, but will most likely take until next weekend to prepare.

lafe avatar Sep 03 '20 08:09 lafe

@marb2000 I uploaded a repro here: https://github.com/lafe/WpfMapDataBindRepro

I did not bother to implement real MVVM in this example as the issue also occurs when you bind directly to the code behind.

lafe avatar Sep 08 '20 11:09 lafe