From: Andrus on

Header("Item1")

returns

<MenuItem Content="Open file" Name="Item1" />

How to change this so it returns Content attribute value "Open file"
corresponding to Name attribute value ?

public static string Header(string entity) {
return Menu.Descendants("MenuItem").Where(m =>
(string)m.Attribute("Name") == entity).Single().ToString();
}

Menu type is XElement and it contains:

<Menu>
<MenuItem Content="File">
<Items>
<MenuItem Content="FilemenuSubMenu1">
<Items>
<MenuItem Content="Open file" Name="Item1" />
<MenuItem Content="Save" Name="Item2" />
.....
<MenuItem IsSeparator="true" />
.....
</Items>
</MenuItem>
<MenuItem Content="FilemenuSubMenu1">
<Items>
.....
</Menu>

Andrus.

From: Arne Vajhøj on
On 25-06-2010 16:51, Andrus wrote:
> Header("Item1")
>
> returns
>
> <MenuItem Content="Open file" Name="Item1" />
>
> How to change this so it returns Content attribute value "Open file"
> corresponding to Name attribute value ?
>
> public static string Header(string entity) {
> return Menu.Descendants("MenuItem").Where(m =>
> (string)m.Attribute("Name") == entity).Single().ToString();
> }

Try:

Menu.Descendants("MenuItem").Where(m => (string)m.Attribute("Name") ==
entity).Single().Attribute("Content").Value

Arne