Contact

+91.22.61488900

 

Synergetics HomeWho We AreWhat We DoOur ApproachTeam

IT Training Services in India

 

 
 

Synergetics IT News Blog - .NET 3.5 FAQ - By Mario Fernades

 
   
.NET 3.5 WPF FAQ: How to remove highlighted attributes in WPF Application

By Mario Fernandes

 


 

Query by Mr. Rajpreet Singh

I have a query in my WPF application.

I was trying to generate XAML styles at runtime using the following code:

XNamespace xmlns = XNamespace.Get("http://schemas.microsoft.com/winfx/2006/xaml/presentation");

XNamespace x = XNamespace.Get("http://schemas.microsoft.com/winfx/2006/xaml");

XDocument xamlDoc = new XDocument(

      new XElement(xmlns + "ResourceDictionary",

            new XAttribute(XNamespace.Xmlns + "x", x.NamespaceName)));

xamlDoc.Root.Add(

      new XElement("SolidColorBrush",

            new XAttribute(x + "Key", "ButtonBrush"),

            new XAttribute("Color", "Red")));

The output which I get is as shown below, but it also brings this (highlighted) useless attribute.

<ResourceDictionary xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

            <SolidColorBrush x:Key="AutoBrush" Color="Black" xmlns="" />

      </ResourceDictionary>

Please tell me what I should change in the code to get rid of this. For now I have manually removed it from the XAML string.

I have also tried combing both the statements into a single one but that also doesn’t help:

XDocument xamlDoc = new XDocument(

new XElement(xmlns + "ResourceDictionary",

new XAttribute(XNamespace.Xmlns + "x", x.NamespaceName),

new XElement("SolidColorBrush",

new XAttribute(x + "Key", "ButtonBrush"),

new XAttribute("Color", "Red"))));

Solutions by Mario Fernandes

(Just add the variable I have marked in green.)

XNamespace xmlns = XNamespace.Get("http://schemas.microsoft.com/winfx/2006/xaml/presentation");

XNamespace x = XNamespace.Get("http://schemas.microsoft.com/winfx/2006/xaml");

XDocument xamlDoc = new XDocument(

      new XElement(xmlns + "ResourceDictionary",

            new XAttribute(XNamespace.Xmlns + "x", x.NamespaceName)));

xamlDoc.Root.Add(

      new XElement(xmlns + "SolidColorBrush",

            new XAttribute(x + "Key", "ButtonBrush"),

            new XAttribute("Color", "Red")));

.

New Technology Adoption Strategy

Microsoft Exchange Server 2010

Technology Direction 2010

SAP Workflow Training

Microsoft Application Virtualization

Agile Methodologies

Oracle 10G SQL

ASP .Net Training Video

ASP .Net Training

Synergetics IT Training Services Team

Innerworkings - India Partner

SQL Server Training in India

SilverLight 3.0 Training in India

Microsoft Training

Best .net Training in India

Visual Studio Team System (VSTS) 2010

Cloud Computing Training

ASP .NET & SQL Server Free Workshop

SQL Server 2008 Training

.NET 3.5 & 4.0 Training

SQL Server 2005 Training

Microsoft Sharepoint Server 2010 Training

Synergetics India AJAX Training

SQL Server & .NET Jobs in Mumbai

SilverLight 4.0 Training Courses

Oracle 10G SQL Training Courses

Core JAVA in Mumbai

MOSS 2010 Training

Java DataBase Connectivity

SQL Server Training Courses

 
 

 

Synergetics is Awarded as the "Best. NET Training Service Provider" by Microsoft.

SQL Server Training Courses | ASP .NET Training | IT Consultant | Microsoft Training

Copyright © 2011 Synergetics IT Training Services India Pvt Ltd.