Silverlight 4 ContextMenu and ScaleTransform - silverlight

The ContextMenu provided by the Silverlight 4 Toolkit worked great until I implemented a
<RenderTransform> tag in my XAML in order to have the Silverlight app scale to fit the entire browser window (following this little tutorial)
When all worked great, before the tutorial, my XAML looked like:
<UserControl>
<Grid>
<!-- Rest of app here... -->
</Grid>
</UserControl>
Now, my app looks like:
<UserControl>
<Canvas>
<Canvas.RenderTransform>
<ScaleTransform [vars]></ScaleTransform>
</Canvas.RenderTransform>
<Grid>
<!-- Rest of app here... -->
</Grid>
</Canvas>
</UserControl>
The scaling works perfectly, but now when I right click, the ContextMenu doesn't appear where it should (under the mouse). Instead, it appears at the same x-position as the mouse, but it shows up at the very top of the app. It's also very buggy, I have to keep clicking around to get it to go away, and I can't right click somewhere else to bring it up again, and it doesn't scale along with the rest of the app.
What might be causing this? Is there a correct way to go about fixing this, or should I just apply an offset to the menu to move it to the mouse?

You will need to pass the cursor coordinates through the inverse of your scale transformation to convert the screen point to a point your application understands.

Related

Maintain position for child in a Canvas with zoom and scroll - WPF

I would like to implement the following functionality.
I have a canvas with several UIElements inside it. The Canvas allows to zoom and scroll applying a scale and translate transforms.
I would like to maintain the red square always in the same position (left bottom corner of the Canvas), to behave as a floating control, so as I change the zoom or the scroll, the red square always maintains it's size and position. Something similar to google maps "Earth window":
What is the best approach to implement it?
NOTE: I tried to use the WPF adorner layer but it does not respond to mouse events, and I need to interact with the red square.
As Clemens said, put it in another layer on top. Grid can host multiple items in the same cell, so create a 1 by 1 Grid for your Canvas add content on top just like any other WPF layout. The later items appear on top (unless Z layer is specified):
<Grid>
<Canvas>
... do all my fancy drawing
</Canvas>
<Rectangle VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="100" Height="100" />
</Grid>
Note, you may have trouble if the canvas has any non WPF rendering, such as video or embedded WindowsForms content. I've seen people have trouble with drawing WPF stuff on top of that.
I also believe you can set Canvas.Bottom="20" to set the position relative to the bottom edge, but I've never used it.

WPF Inkcanvas cann't be seen after saving

I can write well. But WPF Inkcanvas can not be seen after saving in tablet.
but if i use another computer (not tablet), can write and see well.
Your question is not clear. Based on my understanding, I hope that is because the size of the tablet screen which is smaller than the desktop that makes the strokes to get hidden inside the area that was not visible on the tablet, However, the area is visible in Desktop.
Have the InkCanvas inside the Viewbox. I hope that will fix your issue.
<Grid>
<Viewbox Stretch="Fill">
<InkCanvas />
</Viewbox>
</Grid>

How to mix text-only RibbonToggleButton and image-only RibbonButton in Ribbon for WPF?

I'm using the Microsoft Ribbon for WPF October 2010 and have got 3 buttons next to each other, inside a RibbonControlGroup. The left and the right ones are text-only RibbonToggleButton controls, the one in the middle is an image-only RibbonButton. The buttons have a defined width to match the row above.
My code:
<r:RibbonControlGroup>
<r:RibbonToggleButton Width="110" Label="Outgoing" IsChecked="True" />
<!-- Padding and Height set to align the buttons/image -->
<r:RibbonButton Width="30" Padding="5 0" Height="24" SmallImageSource="Images\Small\arrow_swap.png" />
<r:RibbonToggleButton Width="110" Label="Incoming" />
</r:RibbonControlGroup>
The problem is that as soon as I apply the SmallImageSource to the middle button, the other two get spacings for images, causing the text not to be centered anymore. That is problem (1).
Because I didn't find a quick solution, I tried to add the image of the middle button not via SmallImageSource, but by adding it as <Image> for the content of the button. However, the button would remain empty. That is problem (2).
My third solution was to add images to the left and the right button, too. Unfortunately there is nearly no margin between the image and text, which looks quite ugly. I tried several things to enlarge the margin like adding a <Style TargetType="Image"> to the <RibbonToggleButton.Resources>, but although the editor accepts it and displays the spacing at designtime, the margin is gone again at runtime. That is problem (3).
Does anybody have an appropiate solution to any of the three problems? I cannot get it to work. The number of the problems is also the preference of the alternatives, (1) being the most favourite to use with an appropiate hack.
It seems you cannot do that. Its by design.
As per MSDN (here about half way down the page):
Related ribbon controls can be grouped together in a RibbonControlGroup. When a control group is resized, one RibbonControlSizeDefinition is applied to all of the controls in the RibbonControlGroup. The RibbonControlGroup is positioned in the RibbonGroup as if it were one control.
All the controls in a RibbonControlGroup shares the same RibbonControlSizeDefinition. Hence, in your case image will be added for all the buttons.
You may use RibbonGroup instead if you do not want to glue all your controls very closely. This way you can customize each button container by using different RibbonControlSizeDefinitions.

MediaElement audio/video out of sync when inside a ViewBox

I'm using Viewbox controls to proportionally size content in my app at a certain display size. I don't know what the display size of the target computer will be, but I need the app's layout, fonts, graphics, etc to look the same on the target computer as on my machine. Viewbox has worked great for me in the past to accomplish this.
However, when I include a MediaElement (to play a WMV) inside the Viewbox, the media's audio and video get out of sync. The video lags behind, then speeds up, then lags behind, then speeds up, etc.
My actual layout looks something like this:
<Grid>
<Viewbox>
<Grid Width="888" Height="500"> <!-- 16:9 screen size -->
<!-- row definitions -->
<Viewbox Grid.Row="1">
<Grid>
<custom:TransitionFrame />
<!-- TransitionFrame inherits from Frame -->
<!-- TransitionFrame holds a Page that
looks like this:
<Grid>
<MediaElement />
</Grid>
-->
</Grid>
</Viewbox>
</Grid>
</Viewbox>
</Grid>
Any ideas on why this would impact the video? Any ideas on how to resolve it?
Ugh. This has caused me sooooooo much issues. Its really depends on the machine. I have a pretty solid development machine and have never seen any issues. Then I ran the application on another normal machine and it was choppy as hell. I had to play with the following settings:
Switching monitors
Switching screen refresh rates
Switching resolution
Switching graphic cards.
Then when I got the out-of sync issues to < 500ms I created another layout and put in an option saying low graphics and it played fine. I made the other layout very basic with no more than one ViewBox.
I recommend staying away from Viewboxes with MediaElements

Set whole background image/colour in WP7

I can't seem work out (even though I have seen other apps) how to set the whole background of a WP7 page to a image or colour, like in Panorama for example.
If i set
Grid x:Name="LayoutRoot" Background="#FF0079C1"
Or
<Grid.Background>
<ImageBrush ImageSource="/images/highwaysBack.jpg" Stretch="None" />
</Grid.Background>
it still leaves the top info section either black or white depending on the phone setting.
Many thanks.
That's most likely the System Tray. You can hide that by setting shell:SystemTray.IsVisible="False" on your page.
Make a note that hiding the system tray isn't something you always want to do, as you're hiding info like the battery life. Only do it because you app absolutely has to, like a video game. If it's just a simpler app there shouldn't be a real neeed to hide it.

Resources