微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SL beta2 Known Issue

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.@H_502_193@

List of issues

  1. Binding Datagrid with Anonymous type will crash the browser

  2. Pressing “Delete” button after doing a few steps will crash the browser.(I will mention those steps later in this post.)

  3. Controls inside the canvas don’t appear until mouse hovers over them.

  4. TextBox - Cursor will disappear when you add the textBox after removing

  5. dispatcherTimer doesn’t allow event subscription after timer is started

  6. The exception occurs if you hide the button in Click event

  7. TextBox doesn’t work well with non-English keyboard

  8. ScrollBar HorizontalRootElement shows as artifact behind VerticalRootElement

  9. Border.Child - System.ArgumentException and System.AccessViolationException

  10. HorizontalAlignment not respected in Silverlight as in WPF

  11. TextBlock MouseEvent doesn’t work properly when text alignment is applied

  12. 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.xaml

view plaincopy to clipboardprint?

    1. <my:DataGrid x:Name="myDataGrid" Height="200" Width="700" Margin="0,5,10"  

    2. AutoGenerateColumns="True" VerticalAlignment="Top">  

     

    <my:DataGrid x:Name="myDataGrid" Height="200" Width="700" Margin="0,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;  

  •  

    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 += "<Product>";

    str += "<ID>";

    str += "2";

    str += "</ID>";

    str += "<Name>";

    str += "ee";

    str += "</Name>";

    str += "</Product>";

    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.

    1. Pressing “END” button before typing anything in TextBox will disable firing TextChanged event.

    2. 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" />  

     

    <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>  

  •  

    <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>

    </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;  

  • }  

  •  

    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>  

  •  

    <UserControl x:Class="SL2KnownIssue.Page"

    xmlns="http://schemas.microsoft.com/client/2007"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Width="400" Height="300">

    <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">

     

    </Canvas>

    </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);  

  • }  

  •  

    namespace SL2KnownIssue {

    public partial class Page : UserControl {

    TextBox txt = new TextBox();

    public Page() {

    InitializeComponent();

    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,RoutedEventArgs e) {

    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);  

  •  

    _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. @H_502_193@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:class="SL2KnownIssue.Page"></usercontrol>  

  •  

    <UserControl x:Class="SL2KnownIssue.Page"

    xmlns="http://schemas.microsoft.com/client/2007"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Width="400" Height="300">

    <Grid x:Name="LayoutRoot" Background="White">

    <Button x:Name="add" Content="Add"></Button>

    </Grid>

    </UserControl>

    <usercontrol x:class="SL2KnownIssue.Page"></usercontrol>

    2. Attach the Click event in that button and hide it in that event

    add.Visibility = Visibility.Collapsed;  

  • }  

  •  

    public Page() {

    InitializeComponent();

    add.Click += new RoutedEventHandler(add_Click);

    remove.Click += new RoutedEventHandler(remove_Click);

    }

     

    void add_Click(object sender,RoutedEventArgs e) {

    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)

    Disable the button instead of hiding. OR

  • Set 0 to the width and height of button

  • Yi-Lun from Silverlight explained about this issue as below ~

    Credits: Thanks to hotdave2 for reporting this issue and Thanks to Yi-Lun for providing good explanation and workarounds for this issue.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 @H_502_193@this post. @H_502_193@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)

    ElementVerticalTemplate = GetTemplateChild(ElementVerticalTemplateName) as FrameworkElement;  

    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 @R_72_4045@ion: 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 @R_72_4045@ion: 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.@H_502_193@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.@H_502_193@In WPF setting HorizontalAlignment on a control will let it resize itself if it’s inside a stretched 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 stretched 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.@H_502_193@<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">  

     

    <Path x:Name="CurvedBevel" Stretch="Fill" Margin="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>  

  •  

    <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;  

  • }  

  •  

    private void TextBlock_MouseMove(object sender,MouseEventArgs e)

    {

    this.textBlock.FontStyle = FontStyles.Italic;}private void TextBlock_MouseEnter(object sender,MouseEventArgs e)

    {

    this.textBlock.Foreground = highlight;

    }private void TextBlock_MouseLeave(object sender,MouseEventArgs e)

    {

    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.@H_502_193@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.

    版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

    相关推荐