Silverlight 2 (beta1) Known Issues and workarounds (if any)
1 Apr,2008 Silverlight
The following is the List of kNown issues for Silverlight 2 beta 1.
But this is not something new. If you keep on reading Silverlight Forum,you may already aware of those issues. but I wrote this post for those who are not aware of those issues. If you are facing some strange issues,please come and check before spending too much time for finding why something is not working as expected. I hope that you will find it useful. The most of issues are confirmed by Yi-Lun (MSFS) in our forum. (Thanks! Yi-Lun)
If you want to share some SL2 kNown issues that you like to share with everybody,please let me kNow.
List of issues
Binding DatagrID with Anonymous type will crash the browser Pressing “Delete” button after doing a few steps will crash the browser.(I will mention those steps later in this post.) Controls insIDe the canvas don’t appear until mouse hovers over them. TextBox - Cursor will disappear when you add the textBox after removing dispatcherTimer doesn’t allow event subscription after timer is started The exception occurs if you hIDe the button in Click event TextBox doesn’t work well with non-English keyboard Scrollbar HorizontalRootElement shows as artifact behind VerticalRootElement border.Child - System.ArgumentException and System.AccessViolationException HorizontalAlignment not respected in Silverlight as in WPF TextBlock MouseEvent doesn’t work properly when text alignment is applIEd The storePath of Isolated Storage in Application_Startup event and the storepath in Application_Exit event are different.Issue #1: Binding DatagrID with Anonymous type will crash the browser. Source: http://silverlight.net/forums/p/11147/36232.aspxProblem ~Binding DatagrID with Anonymous type will crash the browser
Steps to reproduce ~
Create new SL 2 project. Add DataGrID in Page.xamlview plaincopy to clipboardprint?
<my:DataGrID x:name="myDataGrID" Height="200" WIDth="700" margin="0,5,10" autoGenerateColumns="True" VerticalAlignment="top">
Bind this datagrID with anonymous type.
string str = string.Empty;str = @"<?xml version=""1.0"" encoding=""utf-8"" ?>"; str = "<Products>"; str += "<Product>"; str += "<ID>"; str += "1"; str += "</ID>"; str += "<Name>"; str += "dd"; str += "</Name>"; str += "</Product>"; str += "2"; str += "ee"; str += "</Products>";XDocument xmlSource = XDocument.Parse(str); var products = from p in xmlSource.Descendants("Product") select new { ID = Convert.ToInt32(p.Element("ID").Value), Name = (string)p.Element("Name").Value }; myDataGrid.ItemsSource = products;
Result: Your browser will be hanged or crashed.
Workarounds ~Create the class explicitly Use the Generic List<yourClass> to bind with datagrid
Yi-Lun from Microsoft explained about this issue as below.
Hello,actually the problem is: Anonymous Types are internal. Currently data binding doesn’t support binding to non-public classes. Try to use a ListBox to bind to an internal class,you’ll find a similar problem.
The root cause seems to be: Data binding uses reflection,and reflection needs high security permissions. Silverlight runs in a sand box,where such security permissions are not granted.
However,I found that it’s working fine with Listbox. So,we are still discussing about this issue. I will update this post once we got the final conclusion.
Credit: Thanks to Yi-lun for verifying this issue.
Issue #2: Binding Datagrid with Anonymous type will crash the browser.Source : http://silverlight.net/forums/t/13077.aspxThere are two sub-issues in this issue.
Pressing “END” button before tyPing anything in TextBox will disable firing TextChanged event. After pressing “END” button,type something in textBox. then,Select those text that you type in this textBox and press “DELETE” button. Then,your browser will be crashed.Create new Silverlight 2 project Put the following code in Page.xaml
<TextBox x:Name="Txt" TextChanged="Txt_TextChanged" />
Put the following code in Page.xaml.cs[sourecode langauge="csharp"]
private void Txt_TextChanged(object sender,TextChangedEventArgs e) {
Console.WriteLine(”");
}
[/sourcecode] Set the breakpoint in this event Run the application Press “End” button before typing anything Type something (You will notice that TextChange event is not invoked.) Select those text that you typed by pressing Shit + “HOME” or select with your cursor Press “Delete” key (Your browser will be crashed)
WordaroundsNone:
Credit: Thanks to pavelsua for reporting this issue. He reported the issue 2.1. When I tried to verify his issue,I found another one (2.2). Issue #3. Controls inside the canvas don’t appear until mouse hovers over them.
Source : http://silverlight.net/forums/t/10906.aspxSymptom: A canvas has visibility changed from Visibilty.Collapsed to Visibilty.Visible but controls insIDe the canvas don’t appear until mouse hovers over them.
Steps to reproduce:
1. Create a Silverlight 2 app
2. Change the Page XAML to look like this (either manually or in Blend)
<UserControl x:Class="SilverlightApplication3.Page" xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300"> <Canvas x:Name="LayoutRoot" Background="White"> <Button Height="20" Width="120" Canvas.Left="0" Canvas.Top="0" Content="Button" x:Name="btnTest"/> <Canvas Height="68" Width="120" Canvas.Top="0" Visibility="Collapsed" x:Name="cnvTest"> <Button Height="20" Width="50" Content="Button" Canvas.Top="48"/> </Canvas> </UserControl>
3. Change the Visibility of cnvTest on clicking the button
public Page(){ InitializeComponent(); btnTest.Click += new RoutedEventHandler(btnTest_Click); } void btnTest_Click(object sender, RoutedEventArgs e){ cnvTest.Visibility = Visibility.Visible; }
Expected: the button in the canvas to be shown as soon as the canvas is made visible.
Workarounds ~
Set the initial visibility of the canvas to hide to Visible - set the visibility to Collapsed in the first SizeChanged event Explicitly set the Visibility of the control in the canvas to Visible (even though it already is visible) Use Grid or StackPanel as the container (these both work)Credits: Thanks to AdamJTP for reporting this issue and sharing the workaround.————-
Issue #4. Cursor will disappear when you add the textbox after removingSource : http://silverlight.net/forums/p/11142/36252.aspx: The cursor of textBox won’t show when adding the textBox that is removed earlIEr at runtime.
~
1. The code is written in Page.xaml. There are one button for adding new textBox,another button for removing the textBox and one canvas where the textBox suppose to be added or removed.
<UserControl x:Class="SL2KnownIssue.Page" <Grid x:Name="LayoutRoot" Background="White"> <StackPanel> <Button x:Name="add" Content="Add"></Button> <Button x:Name="remove" Content="Remove"></Button> <Canvas x:Name="placeHolder" Background="Red" Width="100" Height="100"> </StackPanel> </Grid> </UserControl>
2. The code is written in Page.xaml.cs
namespace SL2KnownIssue { public partial class Page : UserControl { TextBox txt = new TextBox(); public Page() { add.Click += new RoutedEventHandler(add_Click); remove.Click += new RoutedEventHandler(remove_Click); void remove_Click(object sender, RoutedEventArgs e) { placeHolder.Children.Remove(txt); void add_Click(object sender,"serif";'>placeHolder.Children.Add(txt); }
3. Run the application
4. Click “Add” button to add the textbox to the screen on the fly.
5. Try to type something in that textbox that you added. (Observe: It will be working fine as you expected.)
6. Click “Remove” button to remove the textbox and click “Add” button again.
7. then,type something in this textbox. (Observe: At this time,you are still able to type it but you won’t see the cursor anymore. )
Initially,I was thinking that the workaround would be “hiding/showing” instead of “removing and adding”. But it won’t work since we already have issue #1. So,I think there is no workaround for that. Be careful when you are trying to remove or add the element.
Credits: Thanks to sgzwkrm for reporting this issue and Yi-Lun for confirming this issue. Issue #5. DispatcherTimer doesn’t allow event subscription after timer is startedSource: http://silverlight.net/forums/p/12652/41581.aspx: dispatcherTimer doesn’t allow any event subscription after timer is started
Steps to reproduce
1. Attach the Tick event to Timer after calling Start() method
_timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromSeconds(0.5); _timer.Start(); _timer.Tick += new EventHandler(_timer_Tick);
Obseve: _timer_Tick will never be called.
Workaround ~Obviously,you have to attach the event before calling Start() method.
Credits: Thanks to Florian Kruesch for reporting this issue and Allen Chen for confirming this issue. Issue #6. The exception occurs if you hIDe the button in Click event Source: http://silverlight.net/forums/p/12519/41100.aspxDescription:
Steps to reproduce ~
1. Add one button in XAML
</UserControl> <usercontrol x:></usercontrol>
2. Attach the Click event in that button and hide it in that event
add.Visibility = Visibility.Collapsed; }
3. Run the application and click the button. (Ob: You will get the following error.)
Error Message:“Error HRESULT E_FAIL has been returned from a call to a COM component”
stack trace :
at MS.Internal.XcpImports.MethodEx(IntPtr ptr,String name,CValue[] cvData)
at System.Windows.DependencyObject.MethodEx(String methodName,CValue[] cvData)
at System.Windows.UIElement.ReleaseMouseCapture()
at System.Windows.Controls.Primitives.ButtonBase.ReleaseMouseCaptureInternal()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(Object sender,MouseButtonEventArgs e)
at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex,Delegate handlerDelegate,Object sender,Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj,IntPtr unmanagedObjArgs,Int32 argsTypeIndex,String eventName)
Yi-Lun from Silverlight explained about this issue as below ~
Issue #7. Textbox doesn’t work well with non-English keyboardSource : http://silverlight.net/forums/t/10705.aspxSome reported that they are not able to type accented characters,like ‘é’,Alt Gr and Ctrl+’,<letter> in textBox if they are using non-English keyboard such as Spanish,German and etc.
None
Credit: Thanks to everyone who are participating in this post. Issue #8. Scrollbar HorizontalRootElement shows as artifact behind VerticalRootElement Source : http://silverlight.net/forums/p/12939/42610.aspx and http://silverlight.net/forums/p/10698/34561.aspxProblem : An artifact of the HorizontalRootElement (from the HorizontalThumbTemplate) is clearly visible.
Steps to reproduce ~
Populate a ListBox control with enough content so that both vertical and horizontal scroll bars appear. copy the default ListBox,Scrollbar,and related templates to App.xaml and wire them up as appropriate Comment out the Track Layer in the VerticalRootElement so that you can see behind the scroll bar An artifact of the HorizontalRootElement (from the HorizontalThumbTemplate) is clearly visible (narrow the vertical bar if you have trouble seeing it)You have to download the source code of Silverlight 2 control from this link <Source Code and Unit Tests for Silverlight 2 Beta 1 Controls> Add the following in OnApplyTemplate method of Scrollbar.
ElementVerticalTemplate = GetTemplateChild(ElementVerticalTemplateName) as FrameworkElement;
Credits: Thanks to jseaver and Attila for reporting this issue and thanks to Attila and Yi-Lun for showing the workarounds.Issue #9. Border.Child - System.ArgumentException and System.AccessViolationExceptionSource: http://silverlight.net/forums/p/11401/36428.aspxUsing SL2B1 with C# (and ie7),the border control will throw an exception if the Child property is set to the same object twice.
Example:
UserControl A;
UserControl B;
myborder.Child = A; //OK
myborder.Child = B; //OK
myborder.Child = B; //Exception
An exception of type ‘System.ArgumentException’ occurred in System.windows.dll but was not handled in user code
Additional information: Value does not fall within the expected range.
Also along these lines,setting Child to null produces another exception,
myborder.Child = null;
An exception of type ‘System.AccessViolationException’ occurred in System.windows.dll but was not handled in user code
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Credit: Thanks to UncleRedz for reporting this issue and Pranav Goel for confirming this issue.Issue #10: HorizontalAlignment not respected in Silverlight as in WPF Source: http://silverlight.net/forums/p/12636/41513.aspxProblems ~
Note: The following is reported by MichaelGG from Silverlight forum.In WPF setting HorizontalAlignment on a control will let it resize itself if it’s insIDe a @R_372_4041@ element. For example:
<Window x:Class=”WpfApplication1.Window1″
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
Title=”Window1″ Height=”auto” WIDth=”auto”>
<GrID>
<StackPanel>
<button Content=”asd” HorizontalAlignment=”Center” />
</StackPanel>
</GrID>
</Window>
This will show a button not much larger than it’s content,centered in the Window. However,doing the same in Silverlight fails:
<UserControl x:Class=”SilverlightApplication1.Page”
xmlns=”http://schemas.microsoft.com/client/2007”
WIDth=”auto” Height=”auto”>
<GrID>
<StackPanel>
<button Content=”asd” HorizontalAlignment=”Center” />
</StackPanel>
</GrID>
</UserControl>
The button is @R_372_4041@ across the entire window.
My WPF-layout-powers are not that strong,so it’s quite possible that I’m missing something here. But it does appear as if SL isn’t behaving how it should.
WorkaroundNote: The following is replIEd from Yi-Lun.<Path x:Name="CurvedBevel" Stretch="Fill" Margin="3,3,0" Data="F1 M 0,0.02 V 0.15 C 0.15,0.22 0.30,0.25 0.50,0.26 C 0.70,0.26 0.85,0.22 1,0.15 V 0.02 L 0.97,0 H 0.02 L 0,0.02 Z">
Nice as it is,this will cause layout problems. Add this Path to a WPF’s Button’s template,and you’ll get the same result. So you have to override the Button’s template,and remove this Path or so…
Issue #11: TextBlock MouseEvent doesn’t work properly when text alignment is applied Source: http://silverlight.net/forums/t/12672.aspxAll Mouse event of TextBlock is not fired when TextAlignment =”Center” .
Steps to reproduces ~Put the following code in XAML (e.g. Page.xaml)
<TextBlock x:Name="textBlock" Width="400" VerticalAlignment="Center" TextAlignment="Center" Text="Center aligned text" MouseMove="TextBlock_MouseMove" MouseEnter="TextBlock_MouseEnter" MouseLeave="TextBlock_MouseLeave"></TextBlock>
Put the following code in C# (e.g. Page.xaml.cs)
private void TextBlock_MouseMove(object sender, MouseEventArgs e) this.textBlock.FontStyle = FontStyles.Italic;}private void TextBlock_MouseEnter(object sender,"serif";'>this.textBlock.Foreground = highlight; }private void TextBlock_MouseLeave(object sender,"serif";'>this.textBlock.Foreground = normal; this.textBlock.FontStyle = FontStyles.Normal; }
Set the breakpoint on those events. Run the application. Move your cursor over the textblock (Ob: No event will be raised.) Remove “TextAlignment=”Center”" Run the application and move the cursor around the textbox (You will get all events that you want so I think the problem is “TextAlignment=”Center”")
Credit: Thanks to Jongho for reporting this issue.Issue #12: The storePath of Isolated Storage in Application_Startup event and the storepath in Application_Exit event are different.
Source: http://silverlight.net/forums/p/12247/42471.aspxThe storePath of Isolated Storage in Application_Startup event and the storepath in Application_Exit event are different.
Download the sample project from this link.(Thanks to Jong Ho for making this sample for me.) Set the breakpoint at Application_Startup event and Application_Exit event Check “storagefile.m_StorePath” in deBUG mode. Please copy this path Close the browser to stop running the application. Check “storagefile.m_StorePath” (You will notice that the paths are different on startup event and exit event.)
A workaround is to cache the isolated storage path in the Startup event,or handle the HTML window.onunload event instead of Silverlight’s Exit event.
Credit: Thanks to bpatters for reporting this issue,Jong Ho for making the demo and Yi-lun for verifying this issue and provIDing the workaround.That’s all for Now. I have 3 or 5 issues in my List. I will update those issue tomorrow or this weekend. If you have any kNown issue of Silverlight 2 beta1,please let me kNow.
以上是内存溢出为你收集整理的SL beta2 Known Issue全部内容,希望文章能够帮你解决SL beta2 Known Issue所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)