I've got an application that reads in XAML files dynamically like this:
StreamReader sr = new StreamReader(pathAndFileName);
this.Content = XamlReader.Load(sr.BaseStream);
In one of those XAML files that gets loaded in (they all have had their code behind removed), this works:
<UserControl
xmlns="http://schemas.microsoft.com/winf...
Hi,
when I use XamlReader.Load() with an invalid XAML string, the resulting XAMLParseException is not caught although beeing in a try-catch-block:
try
{
UIElement xamlCode = XamlReader.Load(XamlText) as UIElement;
}
catch (Exception ex)
{
ErrorText = ex.Message;
}
The code is called from the Tick-Event of a Disp...
I'm trying to create a HierarchicalDataTemplate (from the Silverlight Toolkit) in code in Silverlight following this advice on creating DataTemplates from code: http://stackoverflow.com/questions/59451/creating-a-silverlight-datatemplate-in-code. However, I haven't been able to get it to work for HierarchicalDataTemplate.
I tried using ...
I use the following DataTemplate in many controls:
<pages:BasePageManageItems x:Class="TestApp.Pages.PageManageAddresses"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:pages="clr-namespace:TestHistorierung.Pages"
xmlns:tk="http://schemas.microsoft.com/wpf/2008/toolkit"
xmlns:x="http://schemas....
In a WPF application, I load in xaml files with the xamlreader by finding the current directory like this:
public static string GetApplicationDirectory()
{
return System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
so I can read in a .xaml file by getting its absolute path like this:
string pathAndFileNam...
I have some string representations of Xaml objects, and I want to build the controls. I'm using the XamlReader.Parse function to do this. For a simple control such as Button that has a default constructor not taking any parameters this works fine:
var buttonStr = "<Button xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentatio...
In our app, we need to save properties of objects to the same database table regardless of the type of object, in the form of propertyName, propertyValue, propertyType. We decided to use XamlWriter to save all of the given object's properties. We then use XamlReader to load up the XAML that was created, and turn it back into the value ...
I am trying to save some c# source code into the database. Basically I have a RichTextBox that users can type their code and save that to the database.
When I copy and paste from the visual studio environment, I would like to preserve the formating etc. So I have chosen to save the FlowDocuments Xaml to the database and set this back to...
Im trying to get the specific template in my resource dictionary. This is my resource dictionary
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:view="clr-namespace:Test.Layout.View"
xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:x="http...
The datatemplate for the ListBox is set dynamically by XamlReader.Load. I am subscribing to Checked event by getting the CheckBox object using VisualTreeHelper.GetChild. This event is not getting fired
Code Snippet
public void SetListBox()
{
lstBox.ItemTemplate =
XamlReader.Load(@"<DataTemplate xmlns='http://sch...
Hi,
I am setting the dynamic xaml (I am reading the xaml from the DB) for the content of a tab using the below statement.
Tab.Content = XamlReader.Parse(xaml, ctx)
After setting the content, if I try getting the children using the VisualTreeHelper, but I am not able to get. How ever I dont have this issue when I construct the xaml st...
Ive found out that you can serialize a wpf component, in my example a FixedDocument, using the XamlWriter and a MemoryStream:
FixedDocument doc = GetDocument();
MemoryStream stream = new MemoryStream();
XamlWriter.Save(doc, stream);
And then to get it back:
stream.Seek(0, SeekOrigin.Begin);
FixedDocument result = (FixedDocument)XamlR...
I know that it is possible to parse an XAML - file at runtime and create an UIElement which I can insert into my pages grid, no problem there.
But what I really want is to replace the whole XAML of my page or usercontrol, is that possible, too?
Reasoning:
I want to give the users of my application the opportunity to have the applicati...
hi there,
i'm kind of stuck here. i'm using a dragndrop-library which serializes the dragged UIElements via XamlWriter.Save().
now i'm trying to dragndrop some instances of a class extending Grid. in the constructor i push some elements into the visual tree.
the constructor gets called when the object is deserialized and the elements ...
Do you know if it would be possible to create a framework myself in C# that utilizes the good things that XAML offers, such as dependency properties and data binding?
Or would I have to create everything from scratch myself?
...
hi,
i know the standard XamlWriter does not persist bindings. but what really stinks is that the current value the binding holds does not get serialized too.
my current - really stupid - workaround is to create a DependencyProperty fooProperty and the property foo. and also a property foo2. the Change-eventhandler of foo then writes it...
I am trying to generate XAML from XElements.
<Style xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Style.BasedOn>
<StaticResource>
<StaticResource.ResourceKey>
<Type xmlns="http://schemas.microsoft.com/winfx/2006/xaml">
<Type.TypeName>p:Window</Type.TypeName>
</Type>
...
This works:
XamlReader.Parse("<Pig xmlns=\"clr-namespace:Farm;assembly=Farm\"/>");
This throws The tag 'Pig' does not exist in XML namespace 'clr-namespace:Farm;assembly=Farm':
var context = new ParserContext();
context.XmlnsDictionary.Add("", "clr-namespace:Farm;assembly=Farm");
XamlReader.Parse("<Pig/>", context);
Why?
Farm is t...
I am dynamically building my datatemplate using XamlReader.Parse(string). The problem I have is that I can't put any events on any of the controls I create using the XamlReader. After doing some research online I've learned that this is a known limitation of XamlReader.
I don't know a lot about commands in WPF but could I somehow use t...
Hi
This might be more of an outcry, but building DataTemplates in Silverlight code seems to be impossible. The one option I am aware of being using XamlReader.Load(string), one is met with several issues using this approach:
No validation, everything is done in concatenated strings. We all know this sucks
Any necessary resources have ...