ThinkGeo.com    |     Documentation    |     Premium Support

Refresh problem in WPF

In WPF, when user maximize the window, i need to change also the size of map so the map still covers the whole area:



void Window1_StateChanged(object sender, EventArgs e)
{
    if (Window1.WindowState == WindowState.Maximized)
    {
        wpfMap1.Width = MapGrid.ActualWidth;
        wpfMap1.Height = MapGrid.ActualHeight;
        wpfMap1.Refresh();
    }
}



In doing so, the width and height of wpfMap1 are set correctly to the new width and height of the MapGrid that contains the map, but the map was not refreshed. i have to pan the map so it will be refreshed properly. What am i doing wrong?


 


Ric



Ric,


Thanks for your post!
 
I think if you change the width and height of the map, just try locking the AdormentOverlay before refresh.
 
Try following codes to see it works:

private void Window_StateChanged(object sender, EventArgs e)
        {
            if (Window2.WindowState  == WindowState.Maximized)
            {
                //wpfMap1.Width = 1024;
                //wpfMap1.Height = 800;
                wpfMap1.Width = MapGrid.ActualWidth;
                wpfMap1.Height = MapGrid.ActualHeight;

                try
                {
                    wpfMap1.AdornmentOverlay.Lock.EnterWriteLock();
                }
                finally
                {
                    wpfMap1.AdornmentOverlay.Lock.ExitWriteLock();
                }

                wpfMap1.Refresh();
            }
        }

Let me know if any more questions.


Thanks.
 
Yale

Yale, 
  
 i tried it, it is the same. When i maximize the window, the map portion becomes a blank, i have to pan the map to let the map re-appear in the new maximized window. Also, i dont know whats the logic behind to enter and immediately exit the writelock of AdornmentOverlay.

Ric,


Thanks for your post!
 
Attachment is my sample which you can try it!
 
The reason for the lock of the AdormentOverlay is that the AdormentOverlay is always drawn on top of all other overlays, and when the size changed, we should redraw it instead of using the tiles directly. Personally, I think we should enhance it in our MapControl.
 
Any more questions let me know.
 
Thanks.
 
Yale

986-Post6069_Sample.zip (8.73 KB)

Yale, 
  
 I tried your code on this desktop computer running XP, the map never displayed after window maximized, after i pan it, it did appear. i tried the same code on a XP laptop, the map did appear sometimes, but sometimes did not. For example, when i minimize/maximize VS2008 window, then run again, map did appeared. But you run again (F5), map did not appear.  
  
 i guess it has something to do with graphics cards, i know WPF deals directly with graphic cards, maybe this has nothing to do with MapSuite…? if you know of a solution, please let me know.

Ric, 
  
 Thanks for your post! 
  
 I compile a Exe on VS2008 installed in Windows 7 OS and tested this Exe against the following environment, it seems works fine: 
  
 Window 7(32 bit) 
 Windows XP (32 bit) 
 Windows 2003(32 bit) 
  
 I DONOT think this is related with graphics card, possibly it is related with .net framework environment installed on your machine. Can you double check that the .net framework 3.5 has been installed correctly on your computer running XP? 
  
 Let me know if any more questions. 
  
 Thanks. 
  
 Yale 


Yale, 
  
 Thanks for your effort. Will close this thread, maybe my computer is not installed properly. 
  
 Ric

Ric, You are welcome! 
  
 Please do not hestitate to let me know if any more questions happens! 
  
 Thanks. 
  
 Yale

Yale, 
 I’m having a similar problem. 
 I used the CSharpWpfHowDoISamples->GettingStarted->ZoomInAndOutOfTheMap 
 at the first line of UserControl_Loaded(), i added the line: 
 wpfMap1.Width -= 2; 
  
 As a result the displayed map is blank and you hav to  pan it in order to get it to display properly. 
 his is part of a bigger problem i have which is adjusting the map control size to the window size as the user is changin it 
  
  


Ofer, 
  
 Can you have a try on the sample attached above to see it works correctly on your computer? 
  
 It is a very wield problem! 
  
 Any more question let me know. 
  
 Thanks. 
  
 Yale  


Yale, 
 The sample above works fine on my computer. 
 I added a sizeChanged event handler as following where mapGrid is the name of the grid. 
 When i change the window size, nothin will happen until i pan the map. 
  
 private void Window2_SizeChanged(object sender, SizeChangedEventArgs e) 
         { 
             if (e.PreviousSize.Height==0) 
                 return; 
             wpfMap1.Width = mapGrid.ActualWidth; 
             wpfMap1.Height = mapGrid.ActualHeight; 
             try 
             { 
                 wpfMap1.AdornmentOverlay.Lock.EnterWriteLock(); 
             } 
             finally 
             { 
                 wpfMap1.AdornmentOverlay.Lock.ExitWriteLock(); 
             } 
  
             wpfMap1.Refresh(); 
         }

Ofer, 
  
 Thanks for your post and question! 
  
 Can you paste out your .xaml file or upload a sample for it? I suspect the problem is because that when this event happened, the mapGrid.ActualWidth and mapGrid.ActualHeigh keep the same. 
  
 Let me know if you have any more questions. 
  
 Thanks. 
  
 Yale 


Yale, 
 Following are both the xaml file and the code file. 
 mapGrid.ActualWidth and mapGrid.ActualHeigh  do not keep the same and are changed every time the sizeChanged event is fired. 
  
  
  
 This is the xaml file: 
  
 <Window x:Class="Post6069.Window1" Name="Window2" 
     xmlns="schemas.microsoft.com/winfx/2006/xaml/presentation
     xmlns:x="schemas.microsoft.com/winfx/2006/xaml
     Title="Window1" Height="400" Width="400"  
         xmlns:my="clr-namespace:ThinkGeo.MapSuite.DesktopEdition;assembly=DesktopEdition"  
         Loaded="Window_Loaded" StateChanged="Window_StateChanged" SizeChanged="Window2_SizeChanged"> 
     <Grid Name="mapGrid"> 
         <my:WpfMap Margin="5" Name="wpfMap1"  Width="300" Height="300" /> 
     </Grid> 
 </Window> 
  
 and here is the code file: 
  
 using System; 
 using System.Collections.Generic; 
 using System.Linq; 
 using System.Text; 
 using System.Windows; 
 using System.Windows.Controls; 
 using System.Windows.Data; 
 using System.Windows.Documents; 
 using System.Windows.Input; 
 using System.Windows.Media; 
 using System.Windows.Media.Imaging; 
 using System.Windows.Navigation; 
 using System.Windows.Shapes; 
 using ThinkGeo.MapSuite.DesktopEdition; 
 using ThinkGeo.MapSuite.Core; 
  
 namespace Post6069 
 { 
     ///  
     /// Interaction logic for Window1.xaml 
     ///  
     public partial class Window1 : Window 
     { 
         public Window1() 
         { 
             InitializeComponent(); 
         } 
  
         private void Window_Loaded(object sender, RoutedEventArgs e) 
         { 
             wpfMap1.MapUnit = GeographyUnit.DecimalDegree; 
             wpfMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); 
  
             ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"C:\Program Files\ThinkGeo\Map Suite Desktop Evaluation Edition 3.0 (BETA)\Samples\SampleData\Data\Countries02.shp"); 
             worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1; 
             worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
  
             LayerOverlay worldOverlay = new LayerOverlay(); 
             worldOverlay.Layers.Add("WorldLayer", worldLayer); 
             wpfMap1.Overlays.Add("WorldOverlay", worldOverlay); 
  
             wpfMap1.CurrentExtent = new RectangleShape(-143.4, 109.3, 116.7, -76.3); 
  
             wpfMap1.Refresh(); 
         } 
  
         private void Window_StateChanged(object sender, EventArgs e) 
         { 
             if (Window2.WindowState  == WindowState.Maximized) 
             { 
                 wpfMap1.Width = 1024; 
                 wpfMap1.Height = 800; 
                 //wpfMap1.Width = MapGrid.ActualWidth; 
                 //wpfMap1.Height = MapGrid.ActualHeight; 
  
                 try 
                 { 
                     wpfMap1.AdornmentOverlay.Lock.EnterWriteLock(); 
                 } 
                 finally 
                 { 
                     wpfMap1.AdornmentOverlay.Lock.ExitWriteLock(); 
                 } 
  
                 wpfMap1.Refresh(); 
             } 
         } 
  
         private void Window2_SizeChanged(object sender, SizeChangedEventArgs e) 
         { 
             if (e.PreviousSize.Height==0) 
                 return; 
             wpfMap1.Width = mapGrid.ActualWidth; 
             wpfMap1.Height = mapGrid.ActualHeight; 
             try 
             { 
                 wpfMap1.AdornmentOverlay.Lock.EnterWriteLock(); 
             } 
             finally 
             { 
                 wpfMap1.AdornmentOverlay.Lock.ExitWriteLock(); 
             } 
  
             wpfMap1.Refresh(); 
              
         } 
     } 
 } 


 


Ofer,
 
I am sorry to say that your .xaml file is not complete yet.
 
Because I did not see the MapGrid as well as wpfMap1 defined, following is my .xaml file without MapGrid defined:
 
<Window x:Class="Post6069.Window1" Name="Window2"
    xmlns="schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="400" Width="400" xmlns:my="clr-namespace:ThinkGeo.MapSuite.DesktopEdition;assembly=DesktopEdition" Loaded="Window_Loaded" StateChanged="Window_StateChanged">
    <Grid">
        <my:WpfMap Margin="5" Name="wpfMap1"  Width="300" Height="300" />
    </Grid>
</Window>
 
Let me know if any more questions.
 
Thanks.
 
Yale

Yale, 
 Sorry, I missed the last few lines. here is the full file: 
  
  
 <Window x:Class="Post6069.Window1" Name="Window2" 
     xmlns="schemas.microsoft.com/winfx/2006/xaml/presentation
     xmlns:x="schemas.microsoft.com/winfx/2006/xaml
     Title="Window1" Height="400" Width="400"  
         xmlns:my="clr-namespace:ThinkGeo.MapSuite.DesktopEdition;assembly=DesktopEdition"  
         Loaded="Window_Loaded" StateChanged="Window_StateChanged" SizeChanged="Window2_SizeChanged"> 
     <Grid Name="mapGrid"> 
         <my:WpfMap Margin="5" Name="wpfMap1"  Width="300" Height="300" /> 
     </Grid> 
 </Window> 


Ofer, 
  
 You missed it again! 
  
 Can you use “Add Reply” and upload the file, that absolutely would be complete! 
  
 Thanks. 
  
 Yale 



Yale,


It turns out that when using the quick reply your text  is being cut off if it is too long.


I hope that at my third attempt I'll get it right...


 


<



Window x:Class="Post6069.Window1" Name="Window2"

 


xmlns="schemas.microsoft.com/winfx/2006/xaml/presentation"

 


xmlns:x="schemas.microsoft.com/winfx/2006/xaml"

 


 


 


Title="Window1" Height="400" Width="400" xmlns:my="clr-namespace:ThinkGeo.MapSuite.DesktopEdition;assembly=DesktopEdition" Loaded="Window_Loaded" StateChanged="Window_StateChanged" SizeChanged="Window2_SizeChanged">

 


<Grid Name="mapGrid">

 


<my:WpfMap Margin="5" Name="wpfMap1" Width="300" Height="300" />

 


</


</Grid>Window>

 




Ofer,  
  
 You got it, I will let you know after some investigation. 
  
 Thanks for your patience. 
  
 Yale 


Ofer,  
  
 Unfortunately, we found this is a bug in WPF control, I have added it to our working tracking system. We will try to fix it as soon as possible. 
  
 Thanks for your reporting! 
  
 Let me know if any more questions. 
  
 Thanks. 
  
 Yale 


Hi guys,


Just wondering if this has been fixed as I am running into the same issue.


Thanks!


Ryan