c# - XAML Binding data of an XML attribute and displaying its value -
i making simple rss reader windows phone reads xml file using xml serializer , displays list of items. have rss.css file , amongst others have item class (below fragment):
public class item { [xmlelement("title")] public string title { get; set; } [xmlelement("link")] public string link { get; set; } }
and binding data in xaml files , displaying e.g. title field this:
<listview grid.row="1" itemssource="{binding rss.channel.items}"> <listview.itemtemplate> <datatemplate> <grid> <grid.columndefinitions> <columndefinition width="150" /> <columndefinition width="*" /> </grid.columndefinitions> <textblock text="{binding title}"/>
etc., , it's working fine. now, let's in xml title has attribute, e.g. short="true". how bind , display attribute?
i tried create class under item class:
public class title { [xmlattribute("short")] public string short { get; set; } }
and bind attribute this:
<textblock text="{binding title.short}"/>
but it's not working. can "reach" in xaml somehow or should change in .cs file?
ps. given example shorter alternative problem therefore not logical.
you're binding doesn't exist - title
string
in model. should change deserialization can give both title , attribute:
public class item { [xmlelement("title")] public title title { get; set; } [xmlelement("link")] public string link { get; set; } } public class title { [xmlattribute("short")] public string short { get; set; } [xmltext] public string value { get; set; } }
then current title
binding changes title.value
, title.short
binding should work.
Comments
Post a Comment