This project is read-only.

XamlParseException

Jul 7, 2012 at 7:19 PM

Hello,

All of a sudden the HTMLTextBox is causing an exception:

The property 'Margin' was not found in type 'Section'. [Line: 8 Position: 36]

I've removed all of the attributes and it is still giving this exception. I have to mention that I'm using Bind for the HTML attribute, it was working at the beginning and now all of a sudden it's giving exceptions.

Please help!

Jul 8, 2012 at 10:42 AM

Hello , bassem.

Can you give a code snippet where it occurs?

Jul 8, 2012 at 10:49 AM

Here is the code I'm binding to HTMLViewer/HTMLTextBox that makes a problem:

<p><a href="http://www.mydealz.de/20281/100e-startguthaben-fur-postbank-neukunden-taglich-zwischen-19-und-21-uhr/" class="post_image_link"  title="Permanent link to 100� Startguthaben f?r Postbank Neukunden &#8211; rund um die Uhr am Wochenende *UPDATE5*"><img class="post_image alignleft" src="http://www.mydealz.de/media/webposts-2012/postbank_giro-20120615-175708.png" width="228" height="125" alt="Post image for 100� Startguthaben f?r Postbank Neukunden &#8211; rund um die Uhr am Wochenende *UPDATE5*" /></a>
</p><p><div class="update" style="margin-top: -5px; margin-left: 5px; margin-bottom: 1em; padding-right: 5px; padding-top: 20px; padding-left: 10px; border-style: solid; border-left-width: 0px; border-top-width: 0px; border-right-width: 3px; border-bottom-width: 0px; border-color:#F00; background: url(http://www.mydealz.de/wp-content/themes/myDealZ_final/custom/images/update5.png) no-repeat top right; text-align: justify;"></p>
<p>Die Postbank hat die Aktion anscheinend bis zum 15.07. verl?ngert. Am Wochenende wieder wie gewohnt rund um die Uhr bestellbar (bis Sonntag 24 Uhr).</p>
<p></div>
</p>
<p><div class="update" style="margin-top: -5px; margin-left: 5px; margin-bottom: 1em; padding-right: 5px; padding-top: 20px; padding-left: 10px; border-style: solid; border-left-width: 0px; border-top-width: 0px; border-right-width: 3px; border-bottom-width: 0px; border-color:#F00; background: url(http://www.mydealz.de/wp-content/themes/myDealZ_final/custom/images/update.png) no-repeat top right; text-align: justify;"></p>
<p>Da es in den Kommentaren zu Missverst?ndnissen kam. Die 100� gibt es nat?rlich auch, wenn man das Konto nicht als Gehaltskonto f?hrt.�</div>
</p>
<p>Urspr?nglicher Artikel vom 15.06.2012:</p>
<p>Die <a href="http://www.mydealz.de/tmp/Postbank/34810/"  rel="nofollow" target="_blank">Postbank</a> startet heute wieder mal die <a href="http://www.mydealz.de/tmp/Happy_Hour/34810/"  rel="nofollow" target="_blank">Happy Hour</a>. Wer die Happy Hour von der Postbank noch nicht kennt, kann sich freuen, denn das Angebot richtet sich wie so oft nur an Neukunden (Und�kein Postbank Girokonto in den letzten 6 Monaten besessen habe).</p>
<ul>
<li>Pr?mie: <a href="http://www.mydealz.de/tmp/100_Startguthaben/34810/"  rel="nofollow" target="_blank">100� Startguthaben</a>�(t?glich bis zum <del>06.07.</del> 15.07. zwischen 19 und 21 Uhr)</li>
<li>Kosten: 5,90� pro Monat (bei Geldeingang ab 1000� pro Monat kostenlos � F?r Studenten und Auszubildende generell kostenlos)</li>
<li>Besonderheiten: sehr gro?es Filialnetz, 1 Cent Tankrabatt pro Liter bei Shell bei Zahlung mit der EC-Karte</li>
</ul>
<p>Die 100� Startguthaben werden in der 35. Kalenderwoche (27.8. &#8211; 2.9.) ausgezahlt.</p>
<p>F?r alle die gerne auch mal bei ihrer Bank vor Ort nach dem rechten schauen wollen oder h?ufig pers?nliche Betreuung in Person brauchen, ist man bei den Direktbanken meist falsch und da ist die Postbank vielleicht etwas besser.</p>
<p>Also Student/Azubi die Nachweise bitte direkt bei der Kontoer?ffnung mitschicken und nicht nachreichen (das hat wohl letztes mal nicht 100% zuverl?ssig funktioniert).</p>
<ul>
<li>Kreditkarte: VISA Karte (im 1. Jahr kostenlos � danach 22� / Jahr) / 1,85% Fremdw?hrungseinsatz (wenn man z.B. in Pfund zahlt)</li>
<li>Zinsen (auf dem Tagesgeld-Konto): 2,5% (bis 10.000�) (allerdings nur 6 Monate lang)</li>
<li>Bargeld abheben: kostenlos mit der EC Karte an allen deutschen Filialen der Cash-Group (Deutsche, Dresdner, Commerz, Post und Hypovereinsbank) und einigen Shell Tankstellen. International werden unterschiedliche Geb?hren f?llig bei Bargeldabhebungen mit der VISA Karte.</li>
<li>Einzahlungen: Bei der Postbank</li>
<li>Bermerkung: Die Kontoausz?ge m?ssen einmal pro Quartal online heruntergeladen werden, sonst kommen sie per Post und kosten 0,90� Porto</li>
<li>Manko: Leider kann man bei der Postbank nicht weltweit kostenlos Bargeld abheben und das Konto ist auch nur bedingt kostenfrei</li>
</ul>
<p>Meine pers?nlichen Favouriten bleiben die <a href="http://www.mydealz.de/18694/kostenlose-girokonten-mit-praemien-9-anbieter-150-euro-praemien/"  target="_blank">ING-DiBa, DKB und comdirect</a>, alle aber halt ohne Filialnetz.</p>
<p><a href="http://www.mydealz.de/tmp/link/34810/"  rel="nofollow" target="_blank"><img class="aligncenter" src="http://www.mydealz.de/media/webposts-2012/postbank_giro-20120615-175423.png" alt="" width="416" height="229" /></a><br />
Urspr?ngliches UPDATE4 vom 04.07.2012:</p>
<p><div class="update" style="margin-top: -5px; margin-left: 5px; margin-bottom: 1em; padding-right: 5px; padding-top: 20px; padding-left: 10px; border-style: solid; border-left-width: 0px; border-top-width: 0px; border-right-width: 3px; border-bottom-width: 0px; border-color:#F00; background: url(http://www.mydealz.de/wp-content/themes/myDealZ_final/custom/images/update4.png) no-repeat top right; text-align: justify;"> Wer noch will, muss heute, morgen oder ?bermorgen zuschlagen. </div>
</p>
<p>Urspr?ngliches UPDATE3 vom 30.06.2012:</p>
<p><div class="update" style="margin-top: -5px; margin-left: 5px; margin-bottom: 1em; padding-right: 5px; padding-top: 20px; padding-left: 10px; border-style: solid; border-left-width: 0px; border-top-width: 0px; border-right-width: 3px; border-bottom-width: 0px; border-color:#F00; background: url(http://www.mydealz.de/wp-content/themes/myDealZ_final/custom/images/update3.png) no-repeat top right; text-align: justify;"></p>
<p>So, das letzte Wochenende f?r die�<a href="http://www.mydealz.de/tmp/Postbank_Happy_Hour/34810/"  rel="nofollow" target="_blank">Postbank Happy Hour</a>�ist angebrochen. Am 06.07. l?uft die Aktion aus.</p>
<p></div>
</p>
<p>Urspr?ngliches UPDATE2 vom 23.06.2012:</p>
<p><div class="update" style="margin-top: -5px; margin-left: 5px; margin-bottom: 1em; padding-right: 5px; padding-top: 20px; padding-left: 10px; border-style: solid; border-left-width: 0px; border-top-width: 0px; border-right-width: 3px; border-bottom-width: 0px; border-color:#F00; background: url(http://www.mydealz.de/wp-content/themes/myDealZ_final/custom/images/update2.png) no-repeat top right; text-align: justify;"></p>
<p>Am Wochenende ist durchg?ngig Happy Hour und so kann man seit heute fr?h 9 Uhr bis Sonntag 24 Uhr bei der Postbank zuschlagen. Ab Montag gilt wieder das Zeitfenster 19 &#8211; 21 Uhr.�</div>
</p>

 The Xaml page:

<phone:PhoneApplicationPage 
    x:Class="MyDealz.ShowBlog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:msp="clr-namespace:MSPToolkit.Controls;assembly=MSPToolkit"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
    shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <ScrollViewer Name="scrollViewer" ScrollViewer.HorizontalScrollBarVisibility="Visible" >
        <!--LayoutRoot is the root grid where all page content is placed-->
        <StackPanel>
        <Grid x:Name="LayoutRoot" Background="Transparent" AllowDrop="False" VerticalAlignment="Top" Height="1307">

            <!--TitlePanel contains the name of the application and page title-->

            <!--ContentPanel - place additional content here-->
            
            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0" DataContext="{Binding}" Height="752" VerticalAlignment="Top" Loaded="ContentPanel_Loaded">
                <TextBlock Text="{Binding Title}" Height="106" HorizontalAlignment="Left" Margin="13,6,0,0" Name="titleTextBlock"  VerticalAlignment="Top" Width="437" FontSize="30" TextWrapping="Wrap" FontFamily="Portable User Interface" />
                    <msp:HTMLTextBox  Html="{Binding Content}" />

                        <TextBlock Text="{Binding Dccreator}" Height="30" HorizontalAlignment="Left" Margin="13,121,0,0" Name="userTextBox"  VerticalAlignment="Top" Width="160" />
                <TextBlock Text="{Binding PubDate}" Height="30" HorizontalAlignment="Left" Margin="186,121,0,0" Name="postingDateTextBlock"  VerticalAlignment="Top" Width="264" />


                <TextBlock Height="30" HorizontalAlignment="Left" Name="commentsTextBlock" Text="Comments:" VerticalAlignment="Bottom" Margin="12,0,0,-31" />
                <ListBox Margin="2,786,-14,-34" ItemsSource="{Binding Comments}" DataContext="{Binding BindsDirectlyToSource=True}" Name="commentsListBox" >
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" Margin="0,0,0,17">
                                <StackPanel Width="311">
                                    <TextBlock Text="{Binding Comment_author}" TextWrapping="NoWrap" Style="{StaticResource PhoneTextSubtleStyle}" TextTrimming="WordEllipsis" Width="Auto" Foreground="White" FontFamily="Segoe WP Semibold" />
                                    <!--<msp:HTMLTextBox Html="{Binding Comment_content}" NavigaionPolitic="Manual"/>-->
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>

        </Grid>
        </StackPanel>
    </ScrollViewer>


</phone:PhoneApplicationPage>

Thanks for your help!

Jul 8, 2012 at 3:56 PM

baseem, thx for your report. There is an error in our code. It is linked with the fact that a RichTextBox in Silverlight has very limited functionality. I'll put update that's exclude margin and padding from css parse results in few hours.

FYI: border and background also isn't supported, so if you really need so complicated styles, why not to use webbrowser? 

Jul 8, 2012 at 5:09 PM

because I don't know how to make binding with a webbrowser, if you know that would really help!
Looking forward for the update,

Thanks a lot :) 

Jul 8, 2012 at 7:43 PM
Edited Jul 8, 2012 at 8:13 PM

Hey baseem!

I don't think there is a easy way to bind (to a property, I mean) HTML data to a webbrowser in the MVVM way, but the webbrowser has a NavigateToString method to display data from a HTML string. Would try to write a behavior for that in a couple of days.

Jul 8, 2012 at 8:49 PM

For now you can just use last commit version. Update in downloads and NuGet will be done tomorrow.

Jul 8, 2012 at 9:56 PM

Thanks for the update! 
I'm sorry but I didn't find the dll. can you please tell me where can I find it?
Thanks 

Jul 8, 2012 at 11:05 PM

Because the one I found in the last commit gave the same exception. maybe I'm not using the right one?

Thanks

Jul 9, 2012 at 6:12 AM

I mean last checkin under source code tab.

You can get dll there http://sdrv.ms/MfHkoy

Jul 9, 2012 at 9:59 AM
Edited Jul 9, 2012 at 10:00 AM

I created a behavior to enable WebBrowser content to be updated from an HTML string over binding to a property.

using System.Windows;
using System.Windows.Interactivity;
using Microsoft.Phone.Controls;

namespace WebBrowserHTMLBind
{
    public class WebBrowserHtmlPropertyBehavior : Behavior<WebBrowser>
    {
        private bool _isLoaded;

        public static readonly DependencyProperty HtmlProperty = DependencyProperty.Register("Html", typeof(string),
            typeof(WebBrowserHtmlPropertyBehavior), new PropertyMetadata(null, (o, args) =>
                    {
                        var webBrowserHtmlPropertyBehavior = o as WebBrowserHtmlPropertyBehavior;
                        if (webBrowserHtmlPropertyBehavior != null)
                            webBrowserHtmlPropertyBehavior.NavigateToString((string)args.NewValue);
                    }));

        public string Html
        {
            get { return (string)GetValue(HtmlProperty); }
            set { SetValue(HtmlProperty, value); }
        }

        private void NavigateToString(string html)
        {
            if (_isLoaded && html != null)
                AssociatedObject.NavigateToString(html);
        }

        protected override void OnAttached()
        {
            base.OnAttached();

            AssociatedObject.Loaded += AssociatedObjectLoaded;
        }

        void AssociatedObjectLoaded(object sender, RoutedEventArgs e)
        {
            _isLoaded = true;
            NavigateToString(Html);
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();

            AssociatedObject.Loaded -= AssociatedObjectLoaded;
        }
    }
}

And now you can bind to the Html property:

<phone:WebBrowser Name="webBrowser1" Margin="12,0,12,0" Height="500" VerticalAlignment="Top" HorizontalAlignment="Stretch">
   <i:Interaction.Behaviors>
      <local:WebBrowserHtmlPropertyBehavior Html="{Binding Html}"/>
   </i:Interaction.Behaviors>
</phone:WebBrowser>

and "i" is

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"

Here is my sample.

Jul 9, 2012 at 11:12 AM

Thanks a lot for your update and this webbrowser! it really helps,

However, unfortunately, your dll is still giving an exception for margin although I removed all the margin attributes from the html.

Just a suggestion: can you skip attributes that it doesn't support (not display them, and not throw an exception?)

Thanks

Jul 9, 2012 at 2:30 PM

Baseem, I just try to open your html in our sample using dll I gave you and it opens without exception. Are you sure you use this dll not previous one? Please check your references.