.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Textrange.Load not loading Xaml code into a FlowDocument

Posted By:      Posted Date: September 20, 2010    Points: 0   Category :WPF

I'm trying to convert text with Xaml tags into a FlowDocument.  I've done this before and it worked fine (as far as I can recall - that was about a year ago.)  Now I can't get this to work:

private Span FormatString(String _textToFormat)
    FlowDocument _formattedDocument;
    Span _formattedText;

    _myString = "<FlowDocument xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><Paragraph>This is some <Run FontWeight=\"bold\">bold</Run> text.</Paragraph></FlowDocument>";

    _formattedDocument = new FlowDocument();
    _formattedText = new Span();

    TextRange textRange = new TextRange(_formattedDocument.ContentStart, _formattedDocument.ContentEnd);

    MemoryStream msDocument = new MemoryStream((new ASCIIEncoding()).GetBytes(_myString));
    if (textRange.CanLoad(DataFormats.Xaml))
        textRange.Load(msDocument, DataFormats.Xaml);

// rest of function trimmed - the problem is above

Things work fine up to and including the creation of the MemoryStream (inspection with the debugger shows that the bytes are in there.)  "textRange.CanLoad" also resolves to true, but textRange.Load(msDocument, DataFormats.Xaml) doesn't seem to do anything - after that, a look at "textRa

View Complete Post

More Related Resource Links

How read flowdocument xaml to make available in vb code


I'm very very new to WPF and not particularly experienced in VB.Net (mostly a VBA man) so forgive me if this comes across as completely idiotic, cause it more than likely is :-( .....

The problem I have is that I want the user to have the ability to insert buttons into a richtextbox and be able to put essentially as many buttons as they like in and amongst some text.... simple enough....

Problem is I'm finding this impossible with my limitted knowledge of anything WPF related.....

I can use the following code to allow the user to double click in the rtb at a certain point and the code will go off and create a flowdocument (in vb) with an inline container with a button in it and then merge the text from the rtb with the flowdocument.... 



 Dim WithEvents aButton As TextBox = New TextBox (class level variable)

Dim aFlowDocument As FlowDocument = New FlowDocument

Dim bparagraph As Paragraph = New Paragraph

        bparagraph.Inlines.Add(New InlineUIContainer(aButton))




Designer does not remember my settings, for ex., I want to always load xaml into xaml (code) view, n


I am using VS 2010 Ultimate.  It is not remembering my setup when opening .xaml files.  It is very annonying.  I  am pretty sure VS remembers things like that.

I prefer to load my .xaml file to see the code only.  So I usually minimize the design tab.  However, I have to do this every time I open a .xaml file.

I am getting the feeling this setting is stored at the .sln level, which is even more annonying, it should be global setting for all VS sessions.

Any advice?

Data: More Load, Less Code with the Data Enhancements of ASP.NET 2.0


A data source control is a server control that wraps some basic functions of a data source - be it a SQL Server database, an XML document, an Excel worksheet, or a sitemap description. Through the services of a similar component, data-bound controls can fetch data as well as insert new records or update and delete existing ones. Data source controls enable a consistent model across a variety of data sources and dramatically reduce the amount of code needed to implement a two-way data-binding scenario. This article provides an introduction to data source controls and other related data binding features.

Dino Esposito

MSDN Magazine June 2004

How to load a usercontrol xaml at runtime ???????

Hi, I have a usercontrol xaml created in Expression Blend. Similarly i have xaml for other usercontrols as well. Now i want to draw these controls at runtime on click of buttons, the way it works in VS IDE (Toolbox and Drawing area) Is there any way to load such usercontrols on Canvas at runtime ? What would be the best way to load controls at runtime ?      Programmer

VS 2010 XAML Design View Load always fail with a Type Load Exception

Create a new WPF project in VS and change nothing. The Design View will fail to load with the error below. Error    1    Could not load type 'Microsoft.Expression.DesignModel.Core.ISharedInstanceBuilder' from assembly 'Microsoft.Expression.DesignModel, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Microsoft.Expression.DesignModel is an assembly from Expression Blend. I ever installed Blend 4 RC and uninstall and install Blend 4. I Reflector the assembly I have under Blend 4 bin folder. And cannot find a interface named ISharedInstanceBuilder. But the WPF project is a Template project without any changes. How it get related with Blend 4? And how to fix it? Thanks.  

Can't Load 32-bit Com Object into managed code (C#) in runtime with 64-bit Enviroment

Hey everyoneI need your help with some 64-bit issues. I recently had to migrate my work to a 64-bit enviroment.  I'm using VS 2005.I have a simple c# application that is using an unmanaged c++ Com object. both are 32-bit applicationsBoth projects compile smoothly, and when i register my com object it succeeds. However, during runtime when i try to create an instance of the com class: 'someComClass a = new someComClass()' I get the error:COMException : Retrieving the COM class factory for component with CLSID {XXXXXXXXX} failed due to the following error: 80040154OK people, bring it on, what's wrong ? how do i fix it ? registery issues ? compiler issues ?Any help is welcomedWith thanksOded

How to set Panel.Zindex value though XAML code if any of the Grid/UserControl children having the fo

Hi, I have a Grid with 10 buttons. If any of these buttons has focus then I want to set the Panel.Zindex = 999 for the Grid. How to do this in XAML code?Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This will help other members to find the solution easily.

Package 'Microsoft.VisualStudio.Xaml' has failed to load properly

I can't use WPF designer.I tried some commands to fix it ('devenv /resetskippkgs' & 'devenv /resetsettings') but nothing change.This is the complete error message---------------------------Microsoft Visual Studio---------------------------Package Load FailurePackage 'Microsoft.VisualStudio.Xaml' has failed to load properly ( GUID = {E58C2A8B-BCC4-4559-AD59-D62EB6D58A22} ). Please contact package vendor for assistance. Application restart is recommended, due to possible environment corruption. Would you like to disable loading this package in the future? You may use 'devenv /resetskippkgs' to re-enable package loading.---------------------------Yes   No   ---------------------------Some days ago WPF Designer worked correctly and I didn't install anything new on my pc.Can someone help me ?Many thanks claudio

Can I have a listview load on demand instead of always loading when I use the DATASourceID without h

I know that I can load on demand using the Datasource property instead of the datasourceID.  Is there a way to turn on and off DatasourceID so that it only loads on command with codebehind, yet leave everything else the same with the DatasourceID 

Code inside page load is not executing.

  I am beginner to .Net development, so i am looking for a favour. Thanks a lot in advance!!!!!!! Question 1 :  protected void Page_Load(object sender, EventArgs e)    {        txtUserName.Text = "Focus";                txtUserName.Focus();            } I am unable to get focus to my textbox   Question 2 : I made javascript code for client side validation. function loginjs()        {            if(document.getElementById('txtUserName').value.length==0)            alert("UserName cannot be blank");            else if(document.getElementById('txtPassword').value.length==0)            alert("Password cannot be blank");                    } this code executes but it is not stopping further code execution. I mean it is only alerts but in addition to that i need to stop further execution.     &nbs

Hosted Designer fails to load workflow xaml that has InArguments with default values (xaml saved by

I have hosted the designer in our app. Using the hosted designer, workflows are saved as xaml to a database. When an end user wishes to edit a workflow the xaml is downloaded to a file and loaded into the designer via the .xaml file. The user can also associate assemblies with the workflow and there is a mechanism which makes sure that these assemblies are loaded into the appdomain and available. The problem we are hitting occurs when the top level activity (Sequence) has InArgument with default value. I create a simple Sequence, add InArguments (type of Int32 and String)  and set some default values. I save the workflow xaml to the database and close down the designer. When I wish to edit the workflow and try to load I get the following errors Could not find member '{clr-namespace:}_e905.argument3'. Could not find member '{clr-namespace:}_e905.argument1'. suggesting that some assembly/namespace missing. Here is the xaml I try to load: <Activity mc:Ignorable="sap" x:Class="{x:Null}" this:_e905.argument3="99" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:s="clr-namespace:System;assembly=mscorl

How to set MaxLength on DataGridTextColumn in C# code, not XAML

Hi. Im creating DataGridTextColumns dynamicly in C# but I need to limit the column input length. Is there a way to do it? I tried to use textbox style because textbox has MaxLength property but DataGridTextColumn does not allow to use styles with textbox targettype :( Any ideas please?  

IDE hangs when loading the Fluent XAML Control page

Hi All, This question is related to the MS Fluent WPF RibbonControl samples at http://fluent.codeplex.com. My OS is Vista. But the Fluent suite 1.3 is supposed to be stable. Nevertheless, the 3.5 NET sample apps will execute OK... but when I try to view the "window.xaml" code page in the VS2008 Pro IDE, the page loader hangs (the devenv.exe process consumes 50% of the CPU time) and never completes. Is the IDE configured properly? I'm new to Fluent and just installed the Samples. Also, I installed and uninstalled the MS Ribbon Control samples for WPF. If anyone can help... Please do! Thanks, King

Page load is Loading Twice in gridview on navigating to next page.

Hi All i have implemented master page in my application, in its child page i added GridView control, there i used PagerSettings and its attribute to set paging style. In this i have an optoin to set the mode and its images for navigating to different page. my problem is when i not set any image the page will work correctly if i use any image for its navigate button, then every event is fireing twice. if u have faced same problem, pls answer for this query.. My code is:     <asp:GridView ID="grid" runat="server" AutoGenerateColumns="false" AllowPaging="true"         PageSize="3" OnPageIndexChanging="grid_PageIndexChanging" EnableViewState="true" EnableCaching="true" >         <Columns>             <asp:TemplateField>                 <HeaderTemplate>                     <input type="checkbox" id="CheckALL" runat="server"  enableviewstate="true" />             &nbs

Input parameters from Workflow No-Code Or Xaml Only

I have many activities and a customized workflow Only Xaml and I can not pass a value to a property of a custom activity, following the example of Workflow1.xoml   <pre lang="x-xml"><SequentialWorkflowActivity x:Name="Workflow1" xmlns:ns0="clr-namespace:CustomActivities;Assembly=CustomActivities, Version=, Culture=neutral, PublicKeyToken=null" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow"> <ns0:ReadLineActivity x:Name="readLineActivity1" InputText="" /> <ns0:WriteLineActivity x:Name="writeLineActivity1" OutputText="{ActivityBind readLineActivity1,Path=InputText}" /> </SequentialWorkflowActivity> based on this workflow I pass a value for the property InputText activity readLineActivity1   Thanks a lot!

Cannot create unknown type when loading WF Service from loose Xaml with ActivityXamlServices


I am trying to host a WF4 (RC) Service dynamically. I have a test solution with two projects. The first is a declarative workflow service library with one root Flowchart activity in it, and a simple custom code activity. The workflow service library does not depend on any other custom assemblies or references. The second is my host app, which in my test solution is just a console application.

In my host app, I am attempting to the use ActivityXamlServices to load the Xaml for the workflow service into an activity, and then use the WorkflowServiceHost to fire up a workflow instance using that activity.

As soon as I try to new up the WorkflowServiceHost object, I get this exception...

Cannot create unknown type '{clr-namespace:DeclarativeServiceLibrary1}CodeActivity1'.

If I remove CodeActivity1 from my Flowchart designer, everything runs fine. If I add a direct reference to the workflow service project from my host project and then create a WorkflowServiceHost using an instance of my Flowchart activity instead of the activity created from the Xaml, it also works fine.

It seems to not like using my CodeActivity for some reason when loaded dynamically.

Load Silverlight XAML file into WPF application



I want to load the XAML file of a Silverlight application to set data bindings into WPF window. I am able to load when x:name=classname is removed. But I want to load when it is present. Please help me if there way to achieve this.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend