I'm trying to create a simple table in a WPF FlowDocument that has rotated text in some of the cells. In Microsoft Word you can easily change the text direction of a table cell but I haven't been able to find a way in a WPF FlowDocument.
Any idea on how to rotate the text 90 degrees or change the text direction. I've tried a few things but the text doesn't wrap and size as desired.
Any help would be great. Thanks
Look into using the BlockUIContainer and RotateTransform
Example:
<TableCell>
<BlockUIContainer>
<TextBlock Text="Hello World">
<TextBlock.LayoutTransform>
<RotateTransform Angle="90"></RotateTransform>
</TextBlock.LayoutTransform>
</TextBlock>
</BlockUIContainer>
</TableCell>
Related
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.
I would like to embed an image in an Richtextbox in way that the image is sourrounded by text (should look like a newspaper article which contains some images).
That's what I have until now:
<RichTextBox>
<Paragraph>
<InlineUIContainer>
<Image Source="{Binding Image}" Width="200" Height="100" />
</InlineUIContainer>
<Run Text="{Binding Text}" />
</Paragraph>
</RichTextBox>
This code embedds the image in a way so that the first line of the run starts at the bottom right edge of the image.
But I would like to embedd it such a way:
http://i.stack.imgur.com/NVUNz.jpg
How can this be implemented for WP7.1?
Thanks.
I know this can be done, i believe you would be looking at either Margin or Padding around the image.....As the whole thing will look like an object because that's what it is.
so you want to put Padding or Margin around the image to push the text away from the object giving the appearance of space between the object. Also try Pushing the text to the right and the image to the left.
I hope this will help a little. :)
I don't think it can be done until FlowDocument will be available in Silverlight. Or somebody invents a similar control.
How can I obtain the lenght of a string (given a font , size weight etc) in Pixels? I have seen recomendations to try System.Drawing.Graphics.* but that Assembly / Namespace doesn't seem to be available to me in silverlight.
I hope to center a text box under an image, but the text is provided dynamically.
Since your goal is to Centre the TextBox don't mess around with calculating width etc. Just tell the Container to centre the textbox.
eg.
<Grid>
<Image Source="ToolBox Avatar.png" Stretch="Fill"/>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="TextBlock" TextWrapping="Wrap"/>
</Grid>
Thought I not familiar with developing for Silverlight, I think that this might be of use to you.
I would like to be able to place the word "hello" centered on a specific point. I need to do this completely in XAML without extra code. Best I can tell, all the text alignment properties/styles in XAML act on text within some bounding canvas or other element.
Since I don't know the length of the text I want to center, I can't center it using my own code.
The reason I need to solve the problem entirely in XAML is that I'm not using WPF to create the XAML, I'm writing it directly to an XML DOM. It will then be loaded into a Silverlight or WPF control for display.
In most graphic languages, including SVG, which is where my code originated, text can be aligned against a "stationary point" without a bounding box.
Any suggestions appreciated
(Yes, I know this question is old.)
The effectiveness of this solution may vary with the version of Silverlight or the .NET Framework you are using, and I haven't tried it with Silverlight for Windows Phone 7. I wrote a version for stand-alone WPF applications, and I wrote another version that also works in Silverlight.
First, the version that works in Silverlight and WPF. Please note that you will need to refactor the code a little bit if you aren't using a Canvas to provide an absolute position for the center of your TextBlock. For example, you may be using a TranslateTransform to position your text.
<Canvas>
<Canvas.Resources>
<ScaleTransform x:Key="transform" ScaleX="-1" ScaleY="-1" />
</Canvas.Resources>
<Grid RenderTransform="{StaticResource transform}" RenderTransformOrigin="-.25 -.25">
<TextBlock RenderTransform="{StaticResource transform}">
Hello!
</TextBlock>
</Grid>
</Canvas>
Second, the version that works only in WPF. It doesn't work in Silverlight because it depends on the presence of the Canvas.Right and Canvas.Bottom attached properties. UniformGrid isn't in Silverlight either, but that code could have been replaced by a regular Grid with 2 star-length rows and columns.
<Canvas>
<UniformGrid Rows="2" Columns="2"
DataContext="{Binding ElementName=textBox1}"
Width="{Binding Path=ActualWidth}"
Height="{Binding Path=ActualHeight}">
<Canvas>
<TextBlock Name="textBox1" Canvas.Right="0" Canvas.Bottom="0">
Hello!
</TextBlock>
</Canvas>
</UniformGrid>
</Canvas>
By the way, there may be more efficient ways to solve this problem available. I am making no guarantees!
Lets say I have a canvas defined to be 1000x1000 big. Is it possible to only show a 100x100 part of it in a Viewbox(or a rectangel)?
Any help is apreciated.....
If you work with Brushes, you might want to take a look at Viewbox and Viewport in WPF
Edit: I just realised that Viewbox and Viewport are used for Brushes
This is not really appropiate in your situation. I looked it up, and I think you will like the Clip property on UIElement.
Since Canvas is also a UIElement, you can use the Clip property to simulate a viewport on your Canvas..
Click here for some simple Geometry types
I think you would suffice with a RectangleGeometry
<Canvas>
<Canvas.Clip>
<RectangleGeometry Rect="50,50,25,25" />
</Canvas.Clip>
</Canvas>
Edit #2:
Hehe ok.. if you want your total Canvas displayed, only smaller, perheps you should take a look and LayoutTransform. Then use a ScaleTranform to resize your Canvas ;).
<Canvas>
<Canvas.LayoutTransform>
<ScaleTransform CenterX="0" CenterY="0" ScaleX="0.5" ScaleY="0.5" />
</Canvas.LayoutTransform>
</Canvas>
Tweak the parameters until you receive the desired effect ;)