 |
|
 |
Hi lneir, Your SL version starts text drawing from Top of the Geometry (Say PI/2 Rad) while WPF version starts drawing from Left (Say PI rad). I want the silverlight version to behave like wpf and start drawing text from left, what should I do?
fsd fbfgh hj hfgh tsye5rt y tyty ghnf ghfgh hfhfhg fgh fghds gdfg dfgdf df dfg dfg
|
|
|
|
 |
|
 |
The simply solution is just to rotate the object 90 degrees to the left. You could do this in a number of ways:
1. modify your code to just apply a transform.
2. or more generically modify Generic.xaml template to apply a transform
3. or the best method which is to modify the Update method in the class TextOnAPath. This controls all the drawing updates for the text
I'll leave it as an exercise to the reader
|
|
|
|
 |
|
 |
i want to write the value of the path-lenght on that path with following code:
TextOnAPath.TextOnAPath toP = new TextOnAPath.TextOnAPath();
toP.Text = string.Format(Thread.CurrentThread.CurrentCulture, "{0:F2}", _measuringValue);
Binding textPathBinding = new Binding();
textPathBinding.Source = _myPath.Data.ToString();
textPathBinding.Converter = new PathConverter.StringToPathGeometryConverter();
toP.SetBinding(TextOnAPath.TextOnAPath.TextPathProperty, textPathBinding);
LayoutRoot.Children.Add(toP);
But i don't see any value
i hope, you can help me
|
|
|
|
 |
|
 |
Very useful indeed! Many thanks!
|
|
|
|
 |
|
|
 |
|
 |
Hi! I'm a newbie in Silverlight and I found your article.
This article helped me a lot! Thanks.
But now my question: "Is it possible to do this in Code?"
I tried it like this:
String s = "M0,0 C120,361 230.5,276.5 230.5,276.5 L308.5,237.50001 C308.5,237.50001 419.5,179.5002 367.5,265.49993 315.5,351.49966 238.50028,399.49924 238.50028,399.49924 L61.500017,420.49911";
PathConverter.StringToPathGeometryConverter converter = new PathConverter.StringToPathGeometryConverter();
Geometry g = converter.Convert(s);
TextOnAPath.TextOnAPath toap = new TextOnAPath.TextOnAPath();
toap.Text = "asdfasdfa";
toap.FontSize = 25;
toap.TextPath = g;
toap.DrawLinePath = true;
toap.UpdateLayout();
asdf.Children.Insert(0, toap); //asdf is the name of my canvas
But the canvas stays empty, whats the reason for this?
I hope this question is not too stupid...
EDIT: I found out, that it works in a grid, but not in the canvas...
Thanks
Sternze
modified on Wednesday, July 22, 2009 5:12 AM
|
|
|
|
 |
|
 |
Hmmm...works for me...here is my code behind (paste of your code) and xaml:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace TextOnAPathTestAppSilverlight
{
public partial class PageTest3 : UserControl
{
public PageTest3()
{
InitializeComponent();
String s = "M0,0 C120,361 230.5,276.5 230.5,276.5 L308.5,237.50001 C308.5,237.50001 419.5,179.5002 367.5,265.49993 315.5,351.49966 238.50028,399.49924 238.50028,399.49924 L61.500017,420.49911";
PathConverter.StringToPathGeometryConverter converter = new PathConverter.StringToPathGeometryConverter();
Geometry g = converter.Convert(s);
TextOnAPath.TextOnAPath toap = new TextOnAPath.TextOnAPath();
toap.Text = "asdfasdfa";
toap.FontSize = 25;
toap.TextPath = g;
toap.DrawLinePath = true;
toap.UpdateLayout();
MyCanvas.Children.Insert(0, toap);
}
}
}
<UserControl x:Class="TextOnAPathTestAppSilverlight.PageTest3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Canvas x:Name="MyCanvas"/>
</UserControl>
|
|
|
|
 |
|
 |
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace pathtest
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
String s = "M0,0 C120,361 230.5,276.5 230.5,276.5 L308.5,237.50001 C308.5,237.50001 419.5,179.5002 367.5,265.49993 315.5,351.49966 238.50028,399.49924 238.50028,399.49924 L61.500017,420.49911";
PathConverter.StringToPathGeometryConverter converter = new PathConverter.StringToPathGeometryConverter();
Geometry g = converter.Convert(s);
TextOnAPath.TextOnAPath toap = new TextOnAPath.TextOnAPath();
toap.Text = "asdfasdfdfqadsafasdfa";
toap.FontSize = 25;
toap.TextPath = g;
toap.DrawLinePath = true;
toap.UpdateLayout();
asdf.Children.Insert(0, toap);
}
}
}
XAML:
<UserControl x:Class="pathtest.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="500" Height="500">
<Canvas x:Name="asdf" Background="Transparent" />
</UserControl>
I'm just getting a white WebSite. But if I insert an Alert in front of: 'asdf.Children.Insert(0, toap);', toap is displayed.
EDIT: I found out, it's not always displayed, just sometimes....
Best regards
Sternze
|
|
|
|
 |
|
 |
Hi,
I have tried your code to flatten an Arcsegment. Sometimes it does not return any point, i.e; List is empty.
I have debugged the code and figured it out that the following line is the problem.
double centerDistance = Math.Sqrt(radiusY * radiusY - halfChord * halfChord);
Becuase, when I use small value for radiusY, then halfChord is bigger than radiusY and so centerDistance is NAN.
Kindly help me in this regard, how can I remove that problem.
Best Regards,
Zaheer Ahmad
|
|
|
|
 |
|
 |
Actually I didn't write the section of code, it was borrowed from Charles Petzold. But I would suggest adding a check at this location and setting centerDistance to zero.
|
|
|
|
 |
|
 |
Thank you very much. I have done this, but am not sure will it work 100% or not.
|
|
|
|
 |
|
 |
I'm having the same issue. I put a check in there to see if it was double.IsNAN, but it still doesn't come out right. Did you happen to come up with any resolution to it?
|
|
|
|
 |
|
 |
I'm having the same sort of problem. I was wondering if you would be willing to discuss the issue offline - this is awfully close to what I need (in fact, if I can get this working, that'll probably fix the problem I'm having right now). I'd be willing to pay for help in fixing it (and you could release the fix here as well if you wished).
Will
Williamwgant@yahoo.com
|
|
|
|
 |
|
 |
I'm seeing the following exceptions at run time (Silverlight) and my text is not getting rendered: System.Windows.Data Error: 'MS.Internal.Data.DynamicValueConverter' converter failed to convert value 'Portable User Interface' (type 'System.Windows.Media.FontFamily'); BindingExpression: Path='' DataItem='Portable User Interface' (HashCode=-2088816573); target element is 'TextOnAPath.TextOnAPath' (Name=''); target property is 'internalFontWeight' (type 'System.Windows.FontWeight').. System.InvalidOperationException: Can't convert type System.Windows.Media.FontFamily to type System.Windows.FontWeight. at MS.Internal.Data.DefaultValueConverter.Create(Type sourceType, Type targetType, Boolean targetToSource) at MS.Internal.Data.DynamicValueConverter.EnsureConverter(Type sourceType, Type targetType) at MS.Internal.Data.DynamicValueConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture) at System.Windows.Data.BindingExpression.ConvertToTarget(Object value). here is the XAML: <UserControl x:Class="Inetium.MindMap.UI.Controls.NodeMenu" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:TextOnAPath="clr-namespace:TextOnAPath;assembly=TextOnAPathSilverlight"> <UserControl.Resources> <PathGeometry x:Key="curve0"> <PathGeometry.Figures> <PathFigure StartPoint="37,-3"> <ArcSegment Point="82,43" Size="45,45" SweepDirection="Clockwise"/> </PathFigure> </PathGeometry.Figures> </PathGeometry> </UserControl.Resources> <Canvas Background="White"> <Canvas> <Ellipse Stroke="Black" StrokeThickness="0" Width="110" Height="110"> <Ellipse.Fill> <RadialGradientBrush RadiusX=".7" RadiusY=".7"> <GradientStop Color="Cyan" Offset="1"/> <GradientStop Color="White" Offset="0"/> </RadialGradientBrush> </Ellipse.Fill> </Ellipse> <TextOnAPath:TextOnAPath TextPath="{Binding Source={StaticResource curve0}}" Text="This is a test" DrawLinePath="True" /> </Canvas> </Canvas> </UserControl> Michael Hodnick www.kindohm.com
|
|
|
|
 |
|
 |
Hmmm...I don't get the exception.
Here is what I see when I run with your xaml: screen shot
|
|
|
|
 |
|
 |
Excellent work!
Since your code stops rendering the path when the string ends, I tried to overlap a path with the same geometry, but its not happening, dunno why.
My code follows:
<UserControl x:Class="TextOnAPathTestAppSilverlight.PageTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:core="clr-namespace:System;assembly=mscorlib"
xmlns:PathConverter="clr-namespace:PathConverter;assembly=PathConverter"
xmlns:TextOnAPath="clr-namespace:TextOnAPath;assembly=TextOnAPathSilverlight"
Width="500" Height="500">
<Canvas>
<Canvas.Resources>
<core:String x:Key="MyPath">M 177,182 C 177,182 177,282 258,282 S 258,382 338,382</core:String>
<PathConverter:StringToPathGeometryConverter x:Key="MyPathConverter"/>
</Canvas.Resources>
<Path x:Name="patito" Data="{StaticResource MyPath}" StrokeThickness="1" Stroke="Red" />
<TextOnAPath:TextOnAPath TextPath="{Binding Source={StaticResource MyPath}, Converter={StaticResource MyPathConverter}}"
FontSize="14" DrawLinePath="True"
Text="The quick brown fox jumped ."/>
</Canvas>
</UserControl>
|
|
|
|
 |
|
 |
I hadn't tested the code by putting the control inside a Canvas like you did above...so this turns up a bug! It is fixed by doing two things:
1. Modifying the OnApplyTemplate method in TextOnAPath class to read (basically adding the call to Upated();):
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_layoutPanel = GetTemplateChild("LayoutPanel") as Panel;
if (_layoutPanel == null)
throw new Exception("Could not find template part: LayoutPanel");
_layoutPanel.SizeChanged += new SizeChangedEventHandler(_layoutPanel_SizeChanged);
Update();
}
2. The other part of the problem also requires commenting out the lines below in the Update() method in TextOnAPath:
//if (nextHeight > maxHeight)
//{
// maxHeight = nextHeight;
// _layoutPanel.Margin = new Thickness(maxHeight);
//}
These two things should get the control working when placed inside a Canvas.
Note, when this control is put inside a Canvas element no scaling and translating occurs. This is probably the expected behavior. This occurs because the Canvas Panel (unlike other Panels) goes not gives it's children a size. On the hand when the control is placed inside a Grid (for example), it will be scaled and translated to fit in the size alotted.
Hope that helps.
|
|
|
|
 |
|
 |
Actually instead of commenting out code (as I said above), use the following code instead in the Update() method:
if (nextHeight > maxHeight && !(_newSize.Width == 0) && !(_newSize.Height == 0))
{
maxHeight = nextHeight;
_layoutPanel.Margin = new Thickness(maxHeight);
}
|
|
|
|
 |
|
|
 |
|
 |
Great to hear... There are some additional notes that I will add soon on optimization (e.g., there is a tolerance adjustment to increase/decrease the number of line segments used in the path flattened routine).
|
|
|
|
 |
|
|
 |