Styles in inline-xaml
Last post 05-19-2008 3:42 PM by Sergey Volk MSFT. 6 replies.
Sort Posts:
05-13-2008 5:09 PM
Styles in inline-xaml

Hi! 

Is it possible to work with styles (<Canvas.Style>) when using inline xaml?

I thing it's an Element of Silverlight 2.0, and I'm not sure, if they made it available outside of xaps like TextBoxes or if they put it in an assembly to be transferred inside the xap like Buttons.

Basti8

Loading...
Joined on 03-14-2008
Posts 39
05-14-2008 3:10 AM
Re: Styles in inline-xaml

I tried it this way:

<script id="slscript" type="text/xaml">

<Grid

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

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="250" Height="500">

 

<!--Hintergrund:-->

<Grid.Resources>

<Style x:Key="DefaultStyle" TargetType="TextBlock">

<Setter Property="FontSize" Value="14"/>

</Style>

</Grid.Resources>

 

<TextBlock Text="Test" Style="{StaticResource DefaultStyle}"></TextBlock>

</Grid>

</script>

 

But every time I start this piece of code, no error-message, but the Just-In-Time-Debugger appears. If I delete the <setter>-Element everything starts fine, but of course this way I can't define a style. What's wrong with this?

Basti8

Loading...
Joined on 03-14-2008
Posts 39
05-14-2008 7:49 PM
Re: Styles in inline-xaml

 Hi,

Your XAML seems to be correct, I have just tried pasting it into Visual Studio XAML editor and it works correctly there (for instance 'Test' string appears in visual designer and it changes size when I change FontSize value in Setter. So the problem seems to be not in XAML, but in how you handle it. How are you loading this XAML? Can you show us your code? 

If this answers your question, please click on "Mark as Answer" on this post.

Sergey Volk MSFT

Loading...
Joined on 03-21-2008
Posts 83
05-15-2008 3:36 AM
Re: Styles in inline-xaml

Hi, 

I'm loading it via

<asp:Silverlight id="SL1" runat="server" Source="#slscript" Width="250" Height="500"></asp:Silverlight>

but I also tried to put it into a xaml-file and load from the xaml-file instead of the script. There is always the Just-in-Time-Debugger.

Basti8

Loading...
Joined on 03-14-2008
Posts 39
05-16-2008 5:51 PM
Marked as Answer
Re: Styles in inline-xaml

 Can you try to create HTML page with following content and run it (I've just tried it myself, and it works for me - if it works for you too, then there is probably some problem with instantiation of SL plugin in ASP.NET):

<html>
<head>
    <title>Silverlight Project Test Page</title>
    <script id="slscript" type="text/xaml">
        <Grid
            xmlns="http://schemas.microsoft.com/client/2007"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="250" Height="500">
        <Grid.Resources>
            <Style x:Key="DefaultStyle" TargetType="TextBlock">
                <Setter Property="FontSize" Value="40"/>
            </Style>
        </Grid.Resources>
        <TextBlock Text="MyText" Style="{StaticResource DefaultStyle}" />
        </Grid>  
    </script>
    <script type="text/javascript">
        function onSilverlightError(sender, args) {
            alert("onSilverlightError: " + args.errormessage);
        }
    </script>
</head>

<body>
    <div id="silverlightControlHost">
        <object type="application/x-silverlight" width="600" height="600">
            <param name="source" value="#slscript"/>
            <param name="onerror" value="onSilverlightError" />
        </object>
    </div>
</body>
</html>
 

If this answers your question, please click on "Mark as Answer" on this post.

Sergey Volk MSFT

Loading...
Joined on 03-21-2008
Posts 83
05-19-2008 5:37 AM
Re: Styles in inline-xaml

No, it don't work for me. I copied it to visual studio and when i'm running it, the just-in-time-debugger appears again! But if I delete the "setter"-line everything works...

Basti8

Loading...
Joined on 03-14-2008
Posts 39
05-19-2008 3:42 PM
Marked as Answer
Re: Styles in inline-xaml

 Ok, I have tried my sample with Beta1 bits - and it crashes there indeed, unless setter is removed. Looks like this was a known bug in Beta1, which is fixed by now (because the same HTML page with setter works for me on most recent internal post-Beta1 builds). I'm not aware if there are any workarounds for this issue, so I would suggest you to wait for Beta2 to be released, which should happen relatively soon. Thanks for reporting this issue!
 

If this answers your question, please click on "Mark as Answer" on this post.

Sergey Volk MSFT

Loading...
Joined on 03-21-2008
Posts 83
Page view counter