GMap.Net for WPF Map Position is not updating when Zooming - c#

My WPF application UserControl contains a GMap control.
<UserControl x:Class="Test.test.Map"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:gmmapeprovider="clr-namespace:GMap.NET.MapProviders;assembly=GMap.NET.Core"
xmlns:prism="http://prismlibrary.com/"
xmlns:windowspresentation="clr-namespace:GMap.NET.WindowsPresentation;assembly=GMap.NET.WindowsPresentation" prism:ViewModelLocator.AutoWireViewModel="True">
<Grid >
<windowspresentation:GMapControl
x:Name="mapView" MinZoom="1"
Position="{Binding MapPosition}"
MaxZoom="17"
Zoom="{Binding MapZoom}"
MouseWheelZoomEnabled="True"
MouseWheelZoomType ="MousePositionWithoutCenter"
MapProvider="{x:Static gmmapeprovider:GoogleMapProvider.Instance}"
CacheLoc="{Binding XmlFilePath}"
IgnoreMarkerOnMouseWheel="True"/>
</Grid>
</UserControl>
The Map Position is bound to MapPosition Property in the UserControl's ViewModel. Each time I Pan the Map using the right mouse button, click and drag function, the value of the MapPosition is updated.
Here's my concern:
My expectation is the value of the Position should also be updated if the map is zoomed, while the mouse pointer is not on the center of the control. Apparently, this is not the case, the Position remains unchanged, unless if the map is panned once more.
Am I missing some settings here, or are there any possible workaround for this issue?

I have checked the source code, starting from line 1740 until 1748, it turns out that the very _core._position is the one being updated instead of the GMapControl.Position during MouseWheel Zooming. which means that the UI control itself does not know that the position was been changed apparently.
here's the pull request I have made, hopefully, it gets by the owner.
I have just replaced the _core._position to Position.

Related

How to put an auto show panel over a LibVLCSharp.WPF.VideoView?

I'm writing a WPF desktop application, with some video playback functions. I decided to use LibVLCSharp.WPF to complete the playback task.
Xaml code:
<UserControl ...
xmlns:vlc="clr-namespace:LibVLCSharp.WPF;assembly=LibVLCSharp.WPF"
... >
<vlc:VideoView VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Canvas VerticalAlignment="Stretch" HorizontalAlignment="Stretch" MouseEnter="Canvas_MouseEnter">
</Canvas>
</vlc:VideoView>
</UserControl>
It works fine with playing video, but when I tried to put some hidden controls inside Canvas (or any other type of Panel control) and change their visiblity with MouseEnter event, nothing happens.
While debugging, I found out that MouseEnter event can only fire when Canvas has at least one visible control as its child, and mouse pointer entered that visible control.
I have read the articles about "airspace issue". It seems nothing to do with me since I just want to draw a control layer exactly inside playback area.
Is there any way that I can put an auto show panel on VLC player, which only shows when mouse "hovered" over playback area?
Problem solved with hint from #cube45 . Thank you.
I changed Background of Canvas to something that "not so transparent".
Xaml code:
<Canvas Background="#01000000" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" MouseEnter="Canvas_MouseEnter">
</Canvas>
And mouse events worked. Tricky, but useful.

How to disable all the controls on windows phone by displaying a semi transparent control over the page?

I'd like to have some sort of semi transparent/translucent effect displayed over the entire page and then display my option buttons on top of it but I just can't figure out how and it's driving me nuts! I've seen it in plenty of wp8 apps so it is doable but I just don't know how!
Once this semi transparent/translucent effect is displayed, I want it to dissapeared if clicked on or if one of my option buttons is clicked, and restore the screen as it was or execute an action accordingly.
I've somehow managed to do it by setting the Background colors using a storyboard but strangely enough, once displayed and my options buttons appear, they look fine but once the storyboard is completed, the button then look disabled as well which just looks wrong!!
What is the proper way to give a "Disabled" effect as if you had a semi transparent dialog box displayed over a window.
Any ideas, suggestions or code would be appreciated.
Thanks.
You may be making this more complicated than it needs to be. Consider the following XAML for example:
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid x:Name="ContentRoot">
...
</Grid>
<Grid x:Name="ContentOverlay" Background="#AA000000" Visibility="Collapsed">
...
</Grid>
</Grid>
Both ContentRoot and ContentOverlay will anchor at the top left of the LayoutRoot grid and span the row height. They will stack from furthest to closest in order of declaration, so ContentRoot will be rendered beneath ContentOverlay. Simply manipulate the Visibility of ContentOverlay based on user input.
Alternatively, you can set the Opacity for ContentOverlay to 0 along with collapsed visibility (required so it doesn't intercept hits to the ContentRoot child controls below) and fade it in and out using storyboarding in Blend. That probably looks like a slightly cleaner transition to a user, even if it's only 0.3 seconds long or so.
Use Blend to specify VisualStates (View | States. Then 'states' tab.) You can switch between states in code behind using VisualStateManager.GoToState. One state would be normal, the other all controls disabled.
Mike

ElementFlow element disables controls

I am using the Fluidkit ElementFlow control that I use to display a UserControl that contains textblock with a ScrollViewer as well as button and when they are displayed in the ElementFlow control, all of the buttons and the ScrollViewer seem to be disabled because I can't scroll the ScrollViewer scrollbar and even a simple action as hovering over a button doesn't do anything to the button.
Below is an example of the TextBlock in a ScrollViewer that does not allow for scrolling when used in the ElementFlow.
How can this be fixed?
<ScrollViewer
Height="1200" Width="800"
MaxHeight="1200" MaxWidth="800"
VerticalScrollBarVisibility="Auto">
<TextBlock
Height="Auto" Width="800"
MaxWidth="800"
FontSize="20"
Text="Super long text"
TextWrapping="Wrap"/>
</ScrollViewer>
Just looking over the source code for the project, it looks like it is creating a 3D mesh, and painting the controls on the mesh. This would prevent all user interaction. I don't think there is an easy way to work around this.
However, since you have the source code, you can do the work yourself to make it happen. You're going to need to modify how the ElementFlow represents its items. Look at the CreateMeshModel function. It is currently creating a mesh and applying a VisualBrush to it. Instead, look at the blog post Interacting with 2D on 3D in WPF to figure out what needs to happen.

Place WPF Popup Along Bottom of Screen

I have a Popup that consists of a grid of labels. The popup sits inside a Canvas like this.
<Canvas x:Name="mainCanvas">
<Popup x:Name="mainPopup"
IsOpen="True"
PlacementTarget="{Binding ElementName=mainCanvas}"
PopupAnimation="Fade"
AllowsTransparency="True"
Placement="Center">
Wrapping inside the canvas (or similar control) is the only way I've found to allow the popup's contents to be transparent.
Anyway, all of this works fine and I see my grid of labels across the center of the screen. What I'd really want though is to display the grid of labels across the bottom of the screen. However when I change Placement="Center" to Placement="Bottom", I don't see the popup at all.
Have you seen this? It is a pretty good explanation about how popup placement works.
I created a test WPF project in Blend and pasted your exact code, then changed Placement to Bottom. I did see the content I added to the popup (a TextBlock with some junk text), but it was hard to see, since it is positioned below mainCanvas (as expected).
So... there must be some other problem aside from the code you showed.

Sizing Content to Fill `Client Area` of Window

I am having trouble sizing a WPF control (I'll use the Grid control in this example) to the size of the Client area of a Window. I realize that the Grid automatically fills all available space by default, however I require the Grid's Width to be set manually so that I may bind to it from another control (a DataGrid with one of its column's Width's set to Star if it makes any difference).
Please consider the following XAML:
<Window x:Class="TestApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="768" Width="1024"
x:Name="mainWindow">
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Auto">
<Grid x:Name="testGrid" Background="DarkGray">
</Grid>
</ScrollViewer>
</Window>
And the following Code-Behind:
using System.Windows;
namespace TestApplication
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
testGrid.Width = mainWindow.Width - (SystemParameters.BorderWidth * 2);
}
}
}
When running this simple application, the Grid has a width that is slightly larger than the Client area of the Window, resulting in a Horizontal Scroll Bar being displayed. If SystemParameters.BorderWidth does not accurately calculate the width of the Window's border, what does?
As per the most recent MSDN documentation, SystemParameters.BorderWidth: Gets the metric that determines the border width of the nonclient area of a nonminimized window.
Here is one way of binding the size of the client width with no code-behind:
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Auto">
<Grid x:Name="testGrid" Background="DarkGray" Width="{Binding Content.ActualWidth, ElementName=mainWindow}">
</Grid>
</ScrollViewer>
This uses your named top-level Window and gets with actual width of it's content, a ScrollViewer in this case. If for some reason you want to want the content of the window to be a different size than the window you can enclose it in an empty Grid so this technique still works.
After having fought with this sizing issue for quite some time, I have finally found an elegant solution to the problem. Though I have alread selected #Rick Sladkey's response as the answer (and answer my question it did), I thought I might post my updated understanding in hopes that it might help someone else down the line.
The real frustration point, it turns out, was in dealing with the ScrollViewer. While sizing my content to the ActualWidth of the ScrollViewer worked wonderfully when it's VerticalScrollBar was not visible, things began to break down as soon as my content grew to a vertically scrollable height. Though I had expected the binding on ActualWidth to resize my contol to fit within the viewable area of the ScrollViewer, in reality it remained the same width and became horizontally scrollable as well.
As it turns out, the fix was actually quite simple. Rather than binding the height or width of a control to the ActualHeight or ActualWidth of the ScrollViewer (respectively), bind the height or width of the control to the ViewportHeight or ViewportWidth of the ScrollViewer.
Instead of setting the width manually, how about binding to the grid's ActualWidth property instead (this will give you an actual value)

Categories