Bing maps WPF add location markers - wpf

I have a pushpin on my map, but when I click and drag the map the pushpin stays on the same spot on the screen and doesn't move with the map. How do I put the pushpin on a specific location (coordinates) and have it stay there?
Here is my XAML code:
<Window x:Class="WPFKiosk.MapWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFKiosk"
mc:Ignorable="d"
Title="MapWindow" Height="910" Width="1080" WindowStyle="None" ResizeMode="NoResize">
<!-- -->
<Grid Width="1080" Height="915">
<!-- <Image HorizontalAlignment="Left" Height="644" Margin="20,64,-35,0" VerticalAlignment="Top" Width="1095" Source="Images/map.png"/> -->
<m:Map x:Name="myMap" CredentialsProvider="My_Key" Mode="Road"/>
<m:Pushpin Location="28,-81"
/>
<Image HorizontalAlignment="Left" Height="100" Margin="510,740,0,0" VerticalAlignment="Top" Width="100" Source="Images/iTO Back Arrow.png" MouseLeftButtonDown="Image_MouseLeftButtonDown"/>
</Grid>
</Window>

The Pushpin is not "on the map".
It should look like this:
<m:Map x:Name="myMap" CredentialsProvider="My_Key" Mode="Road">
<m:Pushpin Location="28,-81"/>
</m:Map>

Related

How to retrieve data from a page in a frame on button click c#

private void btnEdit(object sender, RoutedEventArgs e)
{
}
in this button event i want to be able to retrieve two variables from a different xaml which is displayed in the frame of this window. I have no clue how to do this
I have a mainscreen with two buttons and a frame. in this frame i display a page. when this button in the above code is clicked i want to be able to get two variables from the pages textblock on the page. how would i go about this?
i basically need to collect data from the frame to be used in this event
I don't know that your project structure and what you try to do. So I would show you an example on the basis of I understood.
I created the below Page. Page name is "TestPage.xaml"
<Page x:Class="StackOverFlowAnswers.TestPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:StackOverFlowAnswers"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="TestPage">
<Grid>
<TextBlock x:Name="textBlock"/>
</Grid>
</Page>
I created MainWindow that has two button with one frame as below.
Now the source of the Frame is "TestPage.xaml".
<Window x:Class="StackOverFlowAnswers.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:attached="clr-namespace:Parse.WpfControls.AttachedProperties"
xmlns:local="clr-namespace:StackOverFlowAnswers"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<Style x:Key="ConvertableTextBox" TargetType="TextBox">
<Setter Property="attached:CharacterConvertBehavior.ConvertEnable" Value="True"/>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0">
<Button Width="50" Margin="0 0 10 0" Click="Button_Click"/>
<Button Width="50" Margin="0 0 10 0"/>
</StackPanel>
<Grid Grid.Row="1">
<Frame x:Name="mainFrame" Source="TestPage.xaml">
</Frame>
</Grid>
</Grid>
</Window>
Now when the button is clicked would move to the event method of the below.
private void Button_Click(object sender, RoutedEventArgs e)
{
var page = (TestPage)this.mainFrame.Content;
page.textBlock.Text = "test!!!";
}
In the above way, you could access (retrieve) the var of the Page.

Extended WPF Toolkit zoombox disable zoom and reset

I am trying to use the extended toolkit Zoombox in my WPF Application with NET451.
I am using a tabcontrol for navigation and the items are bound to an observablecollection of ContentControls. When i change tab the content is changed but the zoomparameters are not reset. Also i want to disable zooming for certain tabitems. Binding to properties such as scale, minscale and maxscale does not seem to do the trick. My question is, how can i reset/go to home when changing view?
And how can i disable zoom for cetain tabitems?
XAML Looks like:
<Controls:MetroWindow x:Class="Metrotest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:toolkit="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:local="clr-namespace:Metrotest"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Controls:MetroWindow.Resources>
<BooleanToVisibilityConverter x:Key="BoolToVis" />
</Controls:MetroWindow.Resources>
<Grid>
<Grid.DataContext>
<local:MainViewModel/>
</Grid.DataContext>
<TabControl ItemsSource="{Binding tabitems}">
<TabControl.ContentTemplate>
<ItemContainerTemplate>
<Controls:FlipView
IsBannerEnabled="False"
ItemsSource="{Binding flipviewitems}" >
<Controls:FlipView.ItemTemplate>
<DataTemplate>
<toolkit:Zoombox ZoomOn="Content" x:Name="zoombox" AutoWrapContentWithViewbox="False" >
<ContentControl Content="{Binding flipview.Content}"/>
</toolkit:Zoombox>
</DataTemplate>
</Controls:FlipView.ItemTemplate>
</Controls:FlipView>
</ItemContainerTemplate>
</TabControl.ContentTemplate>
</TabControl>
</Grid>
</Controls:MetroWindow>

initial size of element wpf

I have window with this markup
<Window x:Class="TestCloseWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow">
<Button Command="ApplicationCommands.Close">Foo</Button>
</Window>
I'd like to button have MinWidth and MinHeight 100
and MaxHeight and MinHeight equals to 500
And like size window to content so I make this
<Window x:Class="TestCloseWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" SizeToContent="WidthAndHeight" >
<Button MaxHeight="500" MaxWidth="500" MinHeight="100" MinWidth="100" Command="ApplicationCommands.Close">Foo</Button>
</Window>
And I'd like to set initial size of button 200 x 200
without writing Width and Height in window
If I write Width="200" Height="200" in button, button becomes unresizable.
How can I set initial size of control?
I am not sure exactly what you are trying to accomplish, but see if this does what you are wanting. I am using a ViewBox to stretch the Contents when the Window is resized, and setting the contraints in the Window. Be aware that Window Size is different than Window Client Area size.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" MaxHeight="500" MaxWidth="500"
MinWidth="100" MinHeight="100"
Width="200" Height="200">
<Viewbox StretchDirection="Both" Stretch="Fill">
<Button >Hello</Button>
</Viewbox>

how stretch user control in tab control item

Hi I try solve how stretch user control width / height which is active in tab control to tab control width / height.
I use caliburn micro.
I create some user control. Here is it:
<UserControl x:Class="Spirit.Views.TabChatView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Micro="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
xmlns:Controls="clr-namespace:Spirit.Controls" mc:Ignorable="d"
Name="ChatWindow"
Background="{StaticResource LightGrayBackground}"
Height="545" Width="680">[...]</UserControl>
This user control is active in shell, shell declaration is here.
<Window x:Class="Spirit.Views.ChatShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
Title="ChatShellView" Height="300" Width="300">
<DockPanel>
<Button x:Name="OpenTab"
Content="Open Tab"
DockPanel.Dock="Top" />
<TabControl x:Name="Items">
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding DisplayName}" />
<Button Content="X"
cal:Message.Attach="CloseItem($dataContext)" />
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
</DockPanel>
</Window>
Result if some user constrol is active in this shell you can see on this image:
I would like stretch user control on maximum tab control witdh / height.
Remove Height="545" Width="680" in UserControl definition

How can I display my user control in the MainWindow?

I'm trying to build a small MVVM test application, but can't really figure how to display my user control in the MainWindow.
My Solution Explorer:
I got a resource dictionary:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MVVM.ViewModel"
xmlns:vw="clr-namespace:MVVM.View">
<DataTemplate DataType="{x:Type vm:ViewModel}">
<vw:View />
</DataTemplate>
</ResourceDictionary>
I got my view:
<UserControl x:Class="MVVM.View.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<DataTemplate x:Key="PersonTemplate">
<StackPanel>
<TextBlock Text="{Binding FirstName}" />
</StackPanel>
</DataTemplate>
</UserControl.Resources>
<ListBox ItemsSource="{Binding Path=Persons}"
ItemTemplate="{StaticResource PersonTemplate}" />
</UserControl>
and My MainWindow
<Window x:Class="MVVM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MVVM.ViewModel"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary Source="MainWindowResources.xaml" />
</Window.Resources>
<Grid>
</Grid>
</Window>
The most obvious and easiest way is to add the ContentControl element:
<Grid>
<ContentControl x:Name="mainContentControl" />
</Grid>
And after that set the Content property of this control to your view model, and the corresponding view will be loaded and applied automatically:
this.mainContentControl.Content = new ViewModel.ViewModel();
But I would prefer to use another way without datatemplates:
<Grid>
<vw:View x:Name="mainView"/>
</Grid>
this.mainView.DataContext = new ViewModel.ViewModel();
Build your VS2010 solution, then, go to your MainWindow's XAML.
On the left, there is a toolbar with button "Toolbox"
Open it, it contains all the possible WPF controls you could add to your UI
Your UserControl should appear on top of the list (in a category probably named "MVVM Controls"), just drag&drop it to your UI :)

Resources