Canvas RenderTransform error "Cannot convert" in VisualStudio 2010 SilverLight 4 - silverlight

<Canvas Width="945" Height="718" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas RenderTransform="1.333333333,0,0,1.333333333,0,0" />
</Canvas>
This works fine in WPF but the following error in SilverLight
Error 3 Cannot convert "1.333333333,0,0,1.333333333,0,0".

Looks like a MatrixTransform to me, create it explicitly using element syntax as there does not appear to be a type converter.
<Canvas.RenderTransform>
<MatrixTransform>
<MatrixTransform.Matrix>
<!-- I do not know the WPF parsing order
so you'll need to find out what goes where yourself -->
<Matrix OffsetX="???" OffsetY="???"
M11="???" M12="???"
M21="???" M22="???" />
</MatrixTransform.Matrix>
</MatrixTransform>
</Canvas.RenderTransform>
Testing suggest that this is the respective Matrix:
<Matrix M11="1.333333333" M22="1.333333333"/>

Related

PlaneProjection is not working well in silverlight

in silverlight project using name attribute in planeprojection gives Error 1 The type or namespace name 'PlaneProjection' could not be found (are you missing a using directive or an assembly reference?)
code i used for that
<Image Name="blabla.jpg" Height="200" Width="200" >
<Image.Projection>
<PlaneProjection Name="pp" />
</Image.Projection>
</Image>
It is a strange error in that it appears to be complaining about the PlaneProjection itself but that could be a red-herring.
The xaml is not correct because the PlaneProjection does not have a Name property. However you should be able to x:Name. My guess is you are trying to ensure you have a field called pp that you can manipulator in code. You can now use pp as a field in code or find the PlaneProjection using FindName on the control.
This is what I think your Xaml should look like:-
<Image x:Name="MyImage" Source="blabla.jpg" Height="200" Width="200" >
<Image.Projection>
<PlaneProjection x:Name="pp" />
</Image.Projection>
</Image>
TBH, I would simply access the projection as MyImage.Projection rather than add an x:Name to it.

Load Silverlight Canvas as a seperate XAML File?

I want to be able to store various Canvas items in seperate XAML files so for example they are declared as:
<canvas x:Class="Item.One" Height="300" Width="400">
...
</canvas>
and another like this
<canvas x:Class="Item.Two" Height="300" Width="400">
...
</canvas>
I am wondering why I cannot get this to work when I try and load them in as classes I get a parser error, I can do this fine in WPF but not in Silverlight 3.0, what can you do to have to have XAML work as objects rather than resources?
Just to help the Parser error is
AG_E_PARSER_BAD_TYPE
And a real example that does not work:
<Canvas x:Class="Cards.Appointment.ZuneVertical" x:Name="ZuneVertical"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="240" Height="320" Background="White">
</Canvas>
In my code I want to do this:
Preview.Children.Add(Item.One)
Where Preview is a Grid within a ScrollView which is where I want the XAML to be loaded into, ie the Canvas, there a various versions of Canvas I want to load into this Preview Pane, each one is a Class as XAML in WPF, but cannot seem to get this to work in Silverlight 3.0 without the parsing error, tried UserControls but this has the same problem!
Seems it was a problem with the Namespace of my XAML file I added the Application Namespace and this resolves the problem.
<Canvas x:Class="ZuneCardrintouch.Cards.Appointment.ZuneVertical" />

Silverlight: "The name already exists in the tree"

this is a problem that regularly arises when I write Silverlight XAML. In this case, I've made a usercontrol VerticalTabStop (code attached) that has a ToolTip attached. I instanciate a couple of my usercontrols, and then I get the debugging window and the following error:
Line:52
Error: Unhandled Error in Silverlight 2 Application
Code: 2028
Category: ParserError
Message: The name already exists in the tree: AltLabel.
File:
Line: 0
Position: 0
I get an awful lot of these messages as I hover my mouse over the buttons. Any suggestions to what I'm doing wrong here?
Cheers
Nik
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="SLEntityPresenterWebPart.VerticalTabStop"
d:DesignWidth="20" d:DesignHeight="27">
<Grid x:Name="LayoutRoot">
<StackPanel>
<Canvas x:Name="TabStopCanvas" Height="27" Width="20">
<ToolTipService.ToolTip>
<TextBlock x:Name="AltLabel" Text="Substitute me"/>
</ToolTipService.ToolTip>
<Image x:Name="IconImg" Canvas.Left="7" Canvas.Top="9" Width="26" Height="26" Source="Contact.png" Canvas.ZIndex="5" Margin="0,-9,0,0" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="0.85" ScaleY="0.85"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform X="0"/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<Image Source="stop.png" Margin="3,0,0,0"/>
</Canvas>
</StackPanel>
</Grid>
</UserControl>
There is very similar bug even in Silverlight 4.
If you create custom usercontrol, usually:
<UserControl xmlns:MyNameSpace="clr-namespace:MyNameSpace" x:Class="MyNameSpace.MyClass"
x:Name="userControl" ... />
Then, if you add 2 controls without names to the xaml code (with preview):
<MyNameSpace:MyClass ... />
<MyNameSpace:MyClass ... />
There will be exception "The name already exists in the tree: userControl". It occurs because Silverlight can't find the name (unnamed [MyClass]) and looks to the UserControl where it finds "userControl" twice.
One of the solution is to give some names to the controls:
<MyNameSpace:MyClass x:Name = "MyControl1" ... />
Or initialize this control from code:
MyClass control = new MyClass();
SomeGrid.Children.Add(control);
This is a bug in Silvelight. The way to work around it is to remove the Name attribute on the TextBlock in the Tooltip.
I presume that you have the name there for a reason, and that not being able to refer to this element from code is going to be a problem for you. As a work around for that, try replacing the tooltip xaml with this:
<ToolTipService.ToolTip>
<ToolTip x:Name="AltLabel" Content="Substitute me" />
</ToolTipService.ToolTip>
Now you can get to the text by doing AltLabel.Content.
If this does not solve your problem, please let me know.
I was struggling with the same message yesterday...
ParserError - The name already exists in the tree: blah
In my case the problem was that somehow a reference was added... to itself. (The DLL of the project in the projects own bin/debug folder). Removing this reference sorted out the problem.
Seems that this error message is too vague.
Try to remove any name like ' x:Name="TabStopCanvas" ' in stack panel, it worked for me.

How to update Dynamic Resource within a Dynamic Resource?

I have a visual brush which is a group of shapes, the main colour of which is a dynamic resource itself - so the shape is for example MyShape and the Colour, MyColour which is referenced by the Shape object.
My problem is when I update the colour for this - it only happens the first time the shape is loaded (the colour needs to be set first) however as much as I change the colour it won't update the dynamic resource that uses the colour - how do I make this work?
Just need to make a dynamic resource work within another dynamic resource and have them both update when I change the colour.
I have no idea how to get this to work - I spent time creating a colour-picker for WPF only to find I cannot change the colour of this item - 1-Tier resources work where I set the brush/colour directly but not a colour within another object or 2-Tier Resource.
Edit: My problem seems to be specific to using these in a seperate Resource / Dictionary as my program needs to access this item from a class not the Window, the main example mentioned does not work when the MyColor is in a seperate Resource.
Unless I misunderstand the situation, exactly what you're talking about works pretty well. I just tried it out with this Xaml:
<Window x:Class="ConditionalTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<SolidColorBrush x:Key="MyColor" Color="Aqua" />
<VisualBrush x:Key="MyBrush">
<VisualBrush.Visual>
<Ellipse Height="50" Width="100" Fill="{DynamicResource MyColor}" />
</VisualBrush.Visual>
</VisualBrush>
</Window.Resources>
<Grid Background="{DynamicResource MyBrush}">
<Button Height="30" Width="Auto" VerticalAlignment="Center" HorizontalAlignment="Center" Content="ChangeColor" Click="Button_Click" />
</Grid>
</Window>
And then changed the color in the click handler for that button:
private void Button_Click(object sender, RoutedEventArgs e)
{
((SolidColorBrush)Resources["MyColor"]).Color = Colors.Purple;
}
And it worked like a champ.
Can you post an example of how you are attempting to change the color in the resource dictionary?
When I make a sample app and try to change the resource value it appears that the SolidColorBrush in the resource dictionary has been frozen so it can't be modified. To get around this I just set the new value to a new SolidColorBrush.

Reuse of StaticResource in Silverlight 2.0

I am currently testing with Silverlight 2.0 Beta 2, and my goal is to define a resource element once and then reuse it many times in my rendering. This simple example defines a rectangle (myRect) as a resource and then I attempt to reuse it twice -- which fails with the error:
Attribute {StaticResource myRect} value is out of range. [Line: 9 Position: 83]
BTW, this sample works fine in WPF.
<UserControl x:Class="ReuseResourceTest.Page"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="200" Height="200">
<Canvas x:Name="LayoutRoot" Background="Yellow">
<Canvas.Resources>
<RectangleGeometry x:Key="myRect" Rect="25,50,25,50" />
</Canvas.Resources>
<Path Stroke="Black" StrokeThickness="10" Data="{StaticResource myRect}" />
<Path Stroke="White" StrokeThickness="4" Data="{StaticResource myRect}" />
</Canvas>
</UserControl>
Any thoughts on what's up here.
Thanks,
-- Ed
I have also encountered the same problem when trying to reuse components defined as static resources. The workaround I have found is not declaring the controls as resources, but defining styles setting all the properties you need, and instantiating a new control with that style every time you need.
EDIT: The out of range exception you are getting happens when you assign a control to a container that already is inside another container. It also happens in many other scenarios (such as applying a style to an object that already has one), but I believe this is your case.

Resources