I am working on a MonoGame based game which utilizes XAML as the interface. I am however having an issue making sure that the space key does not trigger the XAML interface (it is used for something else in the game). Right now I have a gridview which has items in it. When I hit space, it highlights a an element which I do not want it to do. I have gotten it to not actually select the item, but unfortunately cannot prevent it from highlighting it (and then switching around items using the arrow keys).
Here is a bit of code that does this:
<GridView HorizontalAlignment="Left" Name="Powers" Margin="10,10,0,0" VerticalAlignment="Top" Width="229" Height="163" SelectionMode="None">
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Foreground="white" Width="50"></TextBlock>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</GridView.GroupStyle>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid MaximumRowsOrColumns="4" Orientation="Horizontal" ></VariableSizedWrapGrid>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
is there any way to prevent the highliting of the items through keyboard? I would like to be able to rewire that to the shift key, but one step at a time.
Any help is greatly appreciated!
EDIT: I have poked around in this. I have gotten selection to work the way I want it to. However, the issue is that when I hit space, it highlights and “Checks” my selected grid item which is not what I want. In other words, I got it to highlight as if selected in purple, but when I hit space (for jump in my game) it puts a white box around the item and puts a “Check” into the corner. I want to avoid this. I am putting this question up for higher points. Would really like to know how to solve this.
Ok the trick here is actually to disable the UI elemenet ie. gridview on the backend side. Make sure the element is selected (I don’t think it matters where you set the default to). In your constructor, disable the element. As a result, you now have a valid selection which can be shifted around if need be. However, it will not respond to any input since its disabled. If your using MonoGame for Windows 8 games (since they decided to give up on XNA for some reason), then this is a good way to prevent any keyboard interaction with the UI elements via XAML. You can still obtain input via the XNA side and manipulate your interface that way. As a result, with a disabled interface you can now completely control the UI from the game without any unexpected XAML behavior. If you are doing this for a touch device however, it may or may not be an issue but on a touch device its much easier to manage the UI interaction anyways.