bing maps pushpin and mouseclick - silverlight

I have several pushpins on the map. When i hover with my mouse over the pushpins i get a dialogbox with some information in it. Now i also want some additional information when i click on the same pushpin. But i can't really figure out how to do this. I tried some things but it didn't work...
This is my code:
<bing:MapItemsControl ItemsSource="{Binding Items}">
<bing:MapItemsControl.ItemTemplate>
<DataTemplate>
<bing:Pushpin bing:MapLayer.Position="{Binding Location}" Background="{Binding Color, Converter={StaticResource brushConverter}}">
<ToolTipService.ToolTip>
<StackPanel>
<TextBlock Text="{Binding Address}" />
<TextBlock Text="{Binding Description}" />
</StackPanel>
</ToolTipService.ToolTip>
</bing:Pushpin>
</DataTemplate>
</bing:MapItemsControl.ItemTemplate>
</bing:MapItemsControl>
</bing:Map>
Has somebody tried to do this or know how to do this, by far thanks!

I know this is an old question, but maybe it will shine a little light on the right solution, and help someone else, if not you.
As I understand, the Tooltip stuff is already working, you just want to handle the clicks.
So here are some suggestions:
1 - The novice solution:
You can handle the event from the code behind. Since only Buttons have the Click event, you can't use that, but I think MouseLeftButtonDown, or even better MouseLeftButtonUp are equally good for this. Of course, if you have different maps on different controls, you will have to repeat this code on every one of them.
2 - The advanced solution:
Use Behaviors! They are like tiny extensions that can cling on to controls and extend their functionality. In your place, I would put a Behavior on the Pushpins, that would open a panel to display the info you want. You can read more about this topic under the link above!

Related

Difference between preview and running program

Sorry for my bad headline but I couldn't figure out a better one. Heck, I don't even know how to properly ask my question. But here it comes.
I have a custom control in WPF, let's call it Cell. This control does have a few dependency properties, one Text to show in the Cell and a few "decorative" properties for background color, foreground color and so on. If I use this Cell control stand-alone, everything works fine so far.
Then I have another custom control inheriting from ItemsControl, let's call it Field. This control should show a text and some Cells. it has some "decorative" properties for the text part as well. The information about showing Cells is given to the control by a DataTemplate, something like
<DataTemplate x:Key="CellTemplate"
DataType="...">
<ns:Cell Text="{Binding Text}"
Background="{Binding ...}" />
</DataTemplate>
...
<ns:Field ItemsSource="{Binding Cells}"
ItemTemplate="{StaticResource CellTemplate}" />
If I use this Field control stand-alone, everything works fine so far.
Now I want to show several Field controls at once. So I put an ItemsControl on my window and gave an ItemTemplate again, something like:
<DataTemplate x:Key="CellTemplate"
DataType="...">
<ns:Cell Text="{Binding Text}"
Background="{Binding ...}" />
</DataTemplate>
<DataTemplate x:Key="FieldTemplate"
DataType="...">
<ns:Field ItemsSource="{Binding Cells}"
ItemTemplate="{StaticResource CellTemplate}"
FieldText="{Binding Text}"
TextBackground="{Binding ...}" />
</DataTemplate>
<ItemsControl ItemsSource="{Binding Fields}"
ItemTemplate="{StaticResource FieldTemplate}" />
As long as I preview my WPF window everything works fine so far. Changing the values of some "decorative" properties at Cell level or at Field level is immediately shown in the preview.
But if I run my program it seems that all "decorative" properties at Cell level are ignored. I can see all my Fields with their respective texts and I can see every Cell in every Field with their respective texts. But all Cells are plain white. All set colors are not shown.
Snoop tells me, that every color is set to Transparent by the ParentTemplate.
Visual Studio doesn't show me any exceptions or any binding errors. So I'm kind of stuck at where or how I can find the error and fix it.
So I wanted to ask you, if you may have a hint for me.
Does this contruction with a DataTemplate containing a DataTemplate and both DataTemplates bind to it's DataContext work?
Or does it have something to do with maybe re-using Brush objects that shouldn't be re-used?
But why is it working in the preview?

WPF TabControl and DataGrid bugs, bugs and bugs

for everyone, I found different problems with WPF, the TabControl and the DataGrid. Especially if the TabControl ItemsSource is bound.
Problems i found:
Selection in DataGrid is not visible after switch Tabs back and forth
DataGrid looses sorting on tab switch (SortDescriptions of CollectionView.GetDefaultCollection is cleared on unload)
if a DataGrid cell has focus (is in edit mode) and you click on another tab, two things can happen: 1.) the bound object will not be updated; 2.) if the object is invalid you receive an error DeferRefresh not allowed during edit, or something like this
DataGridComboBox and possibly other controls do clear their values if you switch to another tab if you are working with bound TabControls and DataTemplates. This clears any selection.
So now my question: Is there any ThirdParty controls which perform better in this scenarios?
You also can vote here http://connect.microsoft.com/VisualStudio/feedback/details/807849/databound-tabcontrol-bugs
I got answer from Microsoft it won't fix because not enough people have this problems.
I know some fixes, but they are some really not clean (f.e. using reflection). Maybe you have some ideas?
Hmmm, interesting post though I bet there are all not bugs. I think Microsoft hasnt even taken a look at those things. They might never do. I would appreciate it much if you could post or upload code of all those issues you might be thinking they are all buggy bugs.
Btw, what do you mean with TabControl ItemsSource is bound?
Here is my feedback on this from the info you gave us in the question. 1) You select something, you click away anywhere, no matter if tabitem or another window, you will lose focus, the selection will turn inactive means to slightly grey color. 2) Unloading means removing a control from VisualTree and so CollectionView must be cleared to release memory. This is good so since you dont want memory leaks. 3) If the cell's edit template contains controls which shall update the binding's source on focus lost then for sure that will happen. If you happen to be using a template for TabItems then the template will be mostly reused (means with same instance) and so you might end up taking the seat away from DataGrid' ass which is futhermore not a bug but rather something you wouldnt like to happen to you either. Therefore the DataGrid might be yelling "yo, no fooling around while I am editing a cell". 4) Same as in #3 it depends what you doing and how you define the templates. Consided mostly if template is in resources with a key then the template will be reused.
Just post us code please and let us take a look. I bet you might be doing something very "wpf-unlikely". :)
If those things really happen to be "buggies" (others review the same behavior), I bet there are workarounds for them. :)
Personally I have a feeling that all those things happen because you are using data bound TabControl. Whatever that might mean. I am excited to see what are data bound TabControls and how are they bound? How do you define those templates.
I have the same issue.
Fix to DataGridComboBox issue may be to specify the ItemsSource of the ComboBox as the DataContext property of the TabControl instead of the DataGrid as the DataGrid is removed from the visual tree when you select another tab:
<TabControl x:Name="tabControl" Behaviours:TabContent.IsCached="True">
<TabItem Header="Tab1" Content="{Binding}" ContentTemplate="{StaticResource Tab1}"/>
<TabItem Header="Tab2" Content="{Binding}" ContentTemplate="{StaticResource Tab2}"/>
</TabControl>
<DataTemplate x:Key="Tab1">
<DataGrid ItemsSource="{Binding Entities}" x:Name="dataGrid">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" Header="Name" Width="100"/>
<DataGridTemplateColumn Header="Position" Width="150">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Position}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox SelectedItem="{Binding Position, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding Path=DataContext.Positions, ElementName=tabControl}"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</DataTemplate>

WPF contextmenu mouseover

I am wondering if there is a way to bind the current ContextMenu item to a property in WPF without first clicking on it.
For example:
<MenuItem MaxHeight="20"
HorizontalAlignment="left"
Header="Radio Group"
Name="cmRadio"
ItemsSource="{Binding RadioGroups, Mode=OneWay}" />
I'm hoping to be able to figure out what item the mouse is over before clicking.
Sorry for the lack of description ahead of time.
There are lots of "mouseover" events you could use, some totally in XAML.
Similar Problem
See farther down for the XAML answer.

Silverlight/XNA Data Binding Irregularity

I have to preface this with a disclaimer. I'm a novice programmer, I've tried solving this on my own for days but have now completely run out of ideas/blog posts/walkthroughs and other sources. I really appreciate your time in reading and potentially replying.
I am trying to integrate scoreloop into a game I'm developing but am getting some very strange results with data binding and a listbox. My tests (below) imply that there has to be something I'm doing wrong with bindings, but the crazy thing is it actually works the first time I use it, but not for subsequent levels. Here is the important code I'm using:
XAML:
<ListBox x:Name="LeftListBox" Margin="12,48,0,128" ItemsSource="{Binding}" Background="{x:Null}" HorizontalAlignment="Left" Width="240">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17">
<StackPanel Margin="0,0,0,0" Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Text="{Binding Rank}" TextWrapping="NoWrap" />
<TextBlock Text="." Width="54"/>
<TextBlock Text="{Binding Result}" TextWrapping="NoWrap" Width="76"/>
<TextBlock Text="{Binding User.Login}" TextWrapping="NoWrap"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I have an event registered to fire whenever scores are loaded, this sets the binding and logs a debug message:
LeftListBox.DataContext = App._scoresController.Scores;
Debug.WriteLine("Scores Loaded");
App._scoresController.Scores contains User.Login, Rank, and Result.
After I beat a level it pulls down scores and displays them int he listbox just like I expect. As soon as it goes through the same cycle for the next level though the listbox is blank. The debug line of "Scores Loaded" always gets logged, so I know the event is firing.
What I've done so far in testing:
Turned on ALL for bindings logging and could not see anything getting logged in the output.
Set a break point at the Debug "Scores Loaded" line and can see that everytime it hits there it correctly assigned the datacontext,
with the correct fields with exactly matching names
Tried using Dispatcher.BeginInvoke(LoadScores); to be sure I was doing it off the UI thread in case this was somehow a threading
issue
Set the background color on the stackpanel to a color that I could use to ensure it wasn't being collapsed or hidden by another control
or a storyboard animation
Created a copy of the same listbox, set listbox.datacontext = this in the same LoadScores() method, then set up local variables
for it to bind to. Found that this exhibited the same behavior,
disappearing on the second time I go to set the datacontext
Created a copy of the listbox and removed all bindings, setting the three text fields manually. This would not disappear, but
showed up every time I beat a level
Beat one level (getting it to work), beat another (getting it to disappear), navigate away from the gamepage.xaml/gamepage.xaml.cs where the gameplay takes place (like to a mainpage.xaml, then back to the gamepage. This does not fix the problem, so I'm assuming the problem is higher up than something inside the gamepage.xaml/gamepage.xaml.cs
I feel like I've got to be doing something painfully stupid/obvious, but I'm a novice programmer, just picking pieces up as I have a need, and this is my first venture into the world of data binding.
I would greatly appreciate any suggestions.
Thanks in advance for your time.
I found the problem. I was wrong when I said I was never leaving the GamePage.xaml.cs and Gamepage.xaml.
I reveiwed my code and found that I was actually jumping out to a transition page that lists the details of the next level, then back to GamePage.
Whenever I left the page, strange things would happen to the App._scoresController.Scores. If I created a private _scoresController.Scores within GamePage.xaml.cs and used that instead of the one in App then everything works. It looks like something strange with Scoreloop.

WPF floating listbox

I have a textbox that I would like to combine with a listbox in such a way that when the user types into the textbox, certain items will appear in the listbox, and the user may select them from there. What I am looking for is behaviour similar to that of the AutoCompleteBox. Sadly, I can't use the existing AutocompleBox in my project for several reasons, so I am trying to come up with similar behaviour on my own. Any ideas?
EDIT:
I would like to avoid using the tooltip as this seems like a hack. Also, when the listbox is displayed, no layouts should be changed either in the control or elsewhere. Is there something like the CSS style overflow available?
OK, it looks like "Popup" is what I am looking for. It's got some of its own quirks, but so far it is working just fine. I am pretty much using it like this..
<DockPanel>
<TextBox Text="{Binding Value}"/>
<Popup Name="popOptions" Width="300" Height="100" AllowsTransparency="True" StaysOpen="False">
<ItemsControl ClipToBounds="False" Background="White" MouseLeftButtonUp="ItemsControl_MouseLeftButtonUp">
<sys:String>ITEM ONE</sys:String>
<sys:String>ITEM TWO</sys:String>
<sys:String>ITEM THREE</sys:String>
</ItemsControl>
</Popup>
</DockPanel>
I am capturing other control events to decide when, and when not to display it.
You could put the ListBox in the TextBox's ToolTip
I'm not sure if that's the best way of doing what you're trying to accomplish, but it will work to make a floating listbox

Resources