From: Andrus on 25 Jun 2010 16:51 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 25 Jun 2010 19:02 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
|
Pages: 1 Prev: How to get task manager CPU and default memory column values Next: C#.net 2008 build problem |