Vectorlight News

  • Chat App Converted to HTML and JQuery
    Sep 08, 2011

    Converted from Silverlight to HTML and Javascript/JQuery is the Vectorlight Chat App. Login using your Vectorlight password to chat using your username and avatar.

  • HTML5 iPhone,Android Big Guns Tower Defense
    Jul 02, 2011

    Big Guns has made the leap from Windows Phone 7 (XNA) to HTML5 so you can now play it on your iPhone, Android and other HTML5 compatible devices.

  • HTML5 Games - Word Poppers and Batty
    Jun 04, 2011

    As the take-up of HTML5 quickens (74% of users currently have a browser capable of HTML5 Canvas) we present two more games for both your browser and mobile.

  • Big Guns Tower Defense on Windows Phone 7
    May 06, 2011

    Coming soon to Windows Phone 7 is an XNA port of the popular Vectorlight tower defense game Super Tower Defense. Whilst retaining many of the graphical and gameplay features of the original Silverlight game.

  • Wakacube WP7 Update
    Apr 26, 2011

    Released to the Windows Phone 7 marketplace today is Version 1.1 of Wakacube the 3D physics game of skill. Included in the update are more levels (30 in total) and new mode Wakatime which generates random crate structures to keep players entertained long after the levels have been completed.

  • Home Page News
technical@terrapinn.com
technical@terrapinn.com
RichTextBox and default styles Posted: Jan 18, 2010
 

Hello!


I am trying to use your richtextbox and am coming across a nasty problem which I think must be solvable since I've not seen it mentioned anywhere else.  First of all, I'm running Silverlight 3 on VS 2008.


The goal is to have an HTML editor in my silverlight admin site.  Here is the xaml for my control:

<liquidRichText:RichTextBox x:Name="html_Body" Grid.Row="4" HTML="{Binding Path=Article_Body, Mode=TwoWay}"

                        Padding="0" Margin="0" FontSize="14" AcceptsReturn="True" AutoWrap="True" EnableSpellCheck="False"

                        CreateDefaultStyles="False" EnableGlobalLinkStyle="False" EnablePastingExternalStyles="False"

                        BorderThickness="0" ContentChanged="html_Body_ContentChanged"  />


When I select an article through other controls, all the events are wired nicely so that the parent control is databound to a news article.  The HTML editor here is meant for editting the body of the article.  Below this editor I have this control:

<TextBox x:Name="txt_Body" Grid.Row="5" Text="{Binding Path=Article_Body, Mode=TwoWay}" Visibility="Visible"

                        TextWrapping="Wrap" Padding="0" AcceptsReturn="True" Background="#FFE0E0E0" BorderThickness="2" />


So we effectively have the HTML view and the source view.  However, the richtextbox does not seem to do two-way binding.  Any updates there are not reflected in the textbox below.  Thats okay, I have just added in a method that updates the data object on ContentChanged of the richtextbox.  Now when editting the HTML view, the source view updates - lovely!


However, this is exposing something the richtextbox is doing which I would rather it didn't.  A bunch of default styles are appearing and ravaging through my previously neat source.  This paragraph:

<p>France Telecom SA's mobile unit Orange and U.S.-based Apple Inc. have dropped their exclusivity deals over the distribution of Apple's iPhone handsets in France, the French competition authority said Tuesday.</p>

Turns into:

<p><span class="Normal">France Telecom SA's mobile unit Orange and U.S.-based Apple Inc. have dropped their exclusivity deals over the distribution of Apple's iPhone handsets in France, the French competition authority said Tuesday.</span></p>


Similarly, here is a more violently assaulted paragraph:

<p><span class="Normal">The announcement was made by the companies to the French </span><span class="Normal">competition regulator and comes several months after the </span><span class="Normal">regulator temporarily ruled against the exclusivity deal, in </span><span class="Normal">December 2008, as Orange's domestic competitors Vivendi's </span><span class="Normal">mobile unit SFR and Bouygues' Bouygues Telecom called the deal </span><span class="Normal">into question.</span></p>


And here is the stylesheet inserted at the very beginning:

<style type="text/css">

p {margin:0px 0px 0px 2px;}

ul {margin-top:2px;margin-bottom:2px;}

ol {margin-top:2px;margin-bottom:2px;}

.Normal {font-family:Portable User Interface;font-size:14px;vertical-align:middle;color:#000000;}

.TableDefault {border-collapse:collapse;border:1px solid #000000;}

.TableDefault th {padding:2px;vertical-align:top;text-align:left;border:1px solid #000000;}

.TableDefault td {padding:2px;vertical-align:top;text-align:left;border:1px solid #000000;}

</style>


I have tried to set the CreateDefaultStyles to false, I have also tried to forcably remove all styles and tablestyles from the richtextbox control upon any change of content or databind (as it likes to add more in all the time) but this then causes errors.  It shouldn't be this hard to get it to leave the content alone and just show it.  I must be missing something.


Please help me!  Thank you very much in advance.


Is there also a convenient collection of controls for HTML editting?  Standard sorts of buttons, bold, italic, insert image, insert table - nothing more complicated than that?


Tim

 
 
dan
dan
RE: RichTextBox and default styles Posted: Jan 25, 2010
 

Hi Tim,


Thanks for your post.  The RichTextBox doesn't support 2-way binding at this time.  The problem you have with the styles is simply that the HTML export methods of the RichTextBox are meant only to provide a method for RichText XML content to be displayed as HTML.  The quality of the HTML exported will never be to the standard of HTML imported due to the way the RichTextBox handles styling.


Thanks!

 
 
technical@terrapinn.com
technical@terrapinn.com
RE: RichTextBox and default styles Posted: Jan 27, 2010
 

Okay dokey, thanks very much for the reply!  Maybe I'll make a competitor ;-)

 
 
fender66
fender66
RE: RichTextBox and default styles Posted: Aug 26, 2010
 

Hi Dan


About TwoWay Bindings - are you working on it? Can we expect it soon? (Or are there any problems preventing you from doing so, if yes, I'd be happy to know since I'll try to implement it)


Thanks,

Dänu

 
 
huibvv
huibvv
RE: RichTextBox and default styles Posted: Jan 31, 2012
 

I have been able to get the two way binding working by using a dependencyPropery.  The content of the RichTexbox is loaded with the dependencyPropery value on UserControl Loaded event and updated on the ContentChanged event of the RichTextbox


public string HtmlText

        {

            get { return (string)GetValue(HtmlTextTextProperty); }

            set { SetValue(HtmlTextTextProperty,value); }

        }


        public static readonly DependencyProperty HtmlTextTextProperty =

          DependencyProperty.Register("HtmlText", typeof(string), typeof(CustomRichTextBox), new PropertyMetadata("", HtmlText_PropertyChangedCallback));


        private static void HtmlText_PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)

        {

            //empty

            if (e.NewValue == null)

            {

                (d as CustomRichTextBox).HtmlText = "";

                

            }

        }


private void UserControl_Loaded(object sender, RoutedEventArgs e)

        {

            richTextBox.HTML = HtmlText;

        }


 public CustomRichTextBox()

        {

              InitializeComponent();

              richTextBox.ContentChanged += new RichTextBoxEventHandler(richTextBox_ContentChanged);

              .....

        }


void richTextBox_ContentChanged(object sender, RichTextBoxEventArgs e)

        {

            HtmlText = richTextBox.Save(Format.HTML, RichTextSaveOptions.InlineStyles);

        }

 
 
huibvv
huibvv
RE: RichTextBox and default styles Posted: Jan 31, 2012
 

Looks like i made a mistake, Should be the following:



public string HtmlText

        {

            get { return (string)GetValue(HtmlTextTextProperty); }

            set { SetValue(HtmlTextTextProperty,value); }

        }


        public static readonly DependencyProperty HtmlTextTextProperty =

          DependencyProperty.Register("HtmlText", typeof(string), typeof(CustomRichTextBox), new PropertyMetadata("", HtmlText_PropertyChangedCallback));


        private static void HtmlText_PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)

        {

            //empty

            if (e.NewValue == null)

            {

                (d as CustomRichTextBox).HtmlText = "";


            }

//load initial values first time

            else if (e.NewValue != null && string.IsNullOrEmpty(e.OldValue as string))

            {

                (d as CustomRichTextBox).richTextBox.Load(Format.HTML, e.NewValue.ToString());

            }

        }


void richTextBox_ContentChanged(object sender, RichTextBoxEventArgs e)

        {

            HtmlText = richTextBox.Save(Format.HTML, RichTextSaveOptions.InlineStyles);

        }

 
 

Rate this: 

1 Star 2 Star 3 Star 4 Star 5 Star
9 Ratings / 2.8 Average