Tap into tooltips - silverlight

I made my own overlay... worked great... but then I noticed that it was appearing off the screen (cut off).
I know silverlight has a tooltip control that auto positions itself on the screen instead of letting itself be cut off.
how can I tap into this control? or is there a better way?

<TextBlock>
<ToolTipService.ToolTip>
<ToolTip>
<Overlay /> // This is you overlay
</ToolTip>
</ToolTipService.ToolTip>
</TextBlock>
You can put any content where <Overlay /> is. You can also apply this to any control, I just used a TextBlock for my example.

Related

Button/Image Switch resource using click, MouseEnter and MouseLeave

I'm trying to change an image using events like Click, MouseEnter and MouseLeave. In first place I tried to do it with Buttons in order to have "Click" event too, but I don't know how to remove that lightblue background that appears by default when I put the mouse over the button with a png background.
After this, I tried to use , setting the resource image.png in its Source.
The main problem is that I don't know what to do in code-behind to change between Image Resources in order to change the Source of the control.
I want to know too if I can use a "Click Event" with an control
Update1:
Ok, I tried it by using Binding
For now I think its solved, but I have another problem.
I don't know exactly how to remove that "border". I tried to put the borderbrush property of the buttons to 0, but it seems to be another property or another control.
UI
Thanks.
You can put an image as the content of a button, and add an Click event to that Button. This way, an event gets called when you press the button.
<Button Margin="0,10" Name="mainButton" Click="mainButton_Click">
<Button.Content>
<Image Source="C:/reference-to-image" Height="30"/>
</Button.Content>
</Button>
In the background you can than change the Picture.
This question shows how to do that in the background.
WPF Image UriSource and Data Binding using http:\\ URL
PS. If you want to change the behavior of controls on certain events things like pressing the left mouse button on it, you have to overwrite the event triggers using
<Style TargetType="TextBlock">
<Style.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<EventTrigger.Actions>
...
Hope this helps.
UPDATE
You can set the BorderThickness to 0 and than set the Value of the Padding Property to 0. The Button Control has a predefined padding value, which makes it look like it has a border.
Padding is the space inside the control and the content e.g the space between the button and the picture
<StackPanel Orientation="Horizontal">
<Button Click="Button_Click" Padding="0" BorderThickness="0">
<Image Source="link-to-pic" Height="100"/>
</Button>
<Button Click="Button_Click" Padding="0" BorderThickness="0">
<Image Source="link-to-pic" Height="100"/>
</Button>
</StackPanel>

How do I disable the context menu of FlowDocumentScrollViewer, FlowDocumentPageViewer, or FlowDocumentReader?

When displaying FlowDocument in WPF, how do I disable the right-click context menu of the FlowDocumentScrollViewer, FlowDocumentPageViewer, or FlowDocumentReader?
I'd like a pure-XAML solution that can be used in a style, not one that requires a code-behind.
FlowDocumentScrollViewer and FlowDocumentPageViewer:
You can use ContextMenuService.IsEnabled property.
<FlowDocumentPageViewer ContextMenuService.IsEnabled="False" />
Or set context menu to null using {x:Null} markup extension.
<FlowDocumentPageViewer ContextMenu="{x:Null}" />
I personally prefer first one because is more readable.
FlowDocumentReader:
Above methods doesn't work for FlowDocumentReader, try using this:
<FlowDocumentReader>
<FlowDocument>
<FlowDocument.ContextMenu>
<ContextMenu Visibility="Collapsed" />
</FlowDocument.ContextMenu>
</FlowDocument>
</FlowDocumentReader>

How can I create a complex tooltip in WPF?

I have an Image control on my WPF Window and I'd like to display a complex tooltip when the mouse is hovering over this Image.
Imagine like a spell icon in World of Warcraft, you mouse over and the spells tooltip is shown.
How can I do this in XAML?
You can achieve it like this:
<Image>
<Image.ToolTip>
<ToolTip.Content>
<!--...content goes here. -->
</ToolTip.Content>
</Image.ToolTip>
</Image>
You just put whatever you want into the ToolTip property in XML element syntax.
I recommend doing the following to what x0r stated:
<Image ToolTipService.ShowDuration="1440000">
<Image.ToolTip>
<ToolTip.Content>
<!--...content goes here. -->
</ToolTip.Content>
</Image.ToolTip>
</Image>
This leaves the tooltip open for 24 hours (yes, it's a long time). This is just a way to override that annoying 5-second rule.

ImageButton in Silverlight 3?

For our .NET project this year we have to create a website in Silverlight.
Now I have been getting along nicely utilizing the grid, making gridrows and colums, but I have got to the part where I have to create navigation buttons.
So I decided to go for the following look of the buttons:
Now, when I add a button to my project and I give it the background of that image, this happens.
I have looked at other methods to create an image button but those involve putting an image INSIDE the button using a stackpanel. I tried that and it looks really bad.
This is the code the button generated:
<Button Content="Button" Height="40" Name="button1" Width="125">
<Button.Background>
<ImageBrush ImageSource="/OndernemersAward;component/Images/button.png" Stretch="Fill" />
</Button.Background>
</Button>
I don't know what's going on here and I hope somebody can help me.
Thanks, Thomas
Putting an image inside the button is the best way to go. You can just have an image inside a button, or you could put a StackPanel inside and arrange other content as you see fit. You can also get rid of the border and background brushes on the button so that it is just your image and nothing else. Try this code:
<Button Height="40" Name="button1" Width="125" BorderBrush="{x:Null}" Background="{x:Null}" IsHitTestVisible="False">
<Image Source = "/OndernemersAward;component/Images/button.png"/>
</Button>
That will make a button that is just your image with no other borders, or colors. You can tweak the other settings as you see fit. Note that in order to use the image as the button, you have to delete the Content tag, since the inside of the <Button> takes the place of it.
I ultimately solved this by using blent. I created an image and there is a control there that can transform the image to a button.

Easy way to have checkmark below image for WPF checkbox?

In a WPF window I got a CheckBox containing an image, like this:
<CheckBox>
<Image Source="/Bsoft.Clients.Warenwirtschaft;component/Resources/MyImage.png" />
</CheckBox>
Using this, the checkmark is displayed left to the image.
Is there an easy way to move the checkmark to below the image?
I do not know of an easy way to do this.
You could either use some panel and have a checkbox independent from your image...
<StackPanel>
<Image .../>
<CheckBox .../>
</StackPanel>
Which might not be too much trouble if encapsulated in a UserControl.
Or you change the ControlTemplate of the CheckBox, which is more difficult i think. Default templates can be found on MSDN.

Resources