wpf - Must have non-null value for 'Setter.Property' -
i reading this article on msdn site, in order understand datatrigger.
i have created defaultviewmodel class looks this.
namespace controltemplatedemo { public class defaultviewmodel { private list<todoitem> _list; public defaultviewmodel() { _list = new list<todoitem>(); _list.add(new todoitem { taskname="wedding",priority = 1,description="important wedding",typeoftask = tasktype.home}); _list.add(new todoitem { taskname = "toyota meeting", priority = 3, description = "wsr", typeoftask = tasktype.work }); } public list<todoitem> tasks { { return _list; } } } }
and xamal code this.
<window x:class="controltemplatedemo.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:controltemplatedemo" xmlns:sys="clr-namespace:system;assembly=mscorlib" title="mainwindow" height="350" width="525"> <window.resources> <datatemplate datatype="{x:type local:todoitem}"> <border borderthickness="1" name="myborder" margin="5" padding="5" borderbrush="aqua"> <grid> <grid.rowdefinitions> <rowdefinition/> <rowdefinition/> <rowdefinition/> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition/> <columndefinition/> </grid.columndefinitions> <textblock text="task name" grid.row="0" grid.column="0"/> <textblock text="{binding taskname}" grid.row="0" grid.column="1"/> <textblock text="description:" grid.row="1" grid.column="0"/> <textblock text="{binding description}" grid.row="1" grid.column="1" /> <textblock text="priority:" grid.row="2" grid.column="0"/> <textblock text="{binding priority}" grid.row="2" grid.column="1"/> </grid> </border> <datatemplate.triggers> <datatrigger binding="{binding path=typeoftask}"> <datatrigger.value> <local:tasktype>home</local:tasktype> </datatrigger.value> <setter targetname="myborder" property="background" value="yellow" /> </datatrigger> <multidatatrigger> <multidatatrigger.conditions> <condition binding="{binding path=priority}"> <condition.value> <sys:int32>3</sys:int32> </condition.value> </condition> <condition binding="{binding path=description}"> <condition.value> <sys:string>wsr</sys:string> </condition.value> </condition> </multidatatrigger.conditions> <setter> <setter.targetname>myborder</setter.targetname> <setter.property>background</setter.property> <setter.value>green</setter.value> </setter> </multidatatrigger> </datatemplate.triggers> </datatemplate> <!--<local:defaultviewmodel x:key="dvm"/>--> </window.resources> <grid> <stackpanel> <textblock name="blah" fontsize="20" text="my tasks."/> <listbox x:name="lsttasks" itemssource="{binding path=tasks}" horizontalcontentalignment="stretch" > </listbox> </stackpanel> </grid>
qeustion/problem:
using datatemplate reder data inside listbox. intention highlight background of border ( border of list item ) depending on multiple conditions. e.g. if taskpriorty 3 , taskdescription 'wsr' want highlight list item red color. when running application getting runtime error below message. must have non-null value 'setter.property'.
can me find out problem? without multidatatrigger working fine.
thanks, hemant
use attribute syntax instead of property element syntax
<multidatatrigger> <multidatatrigger.conditions> ... </multidatatrigger.conditions> <setter targetname="myborder" property="background" value="green"/> </multidatatrigger>
Comments
Post a Comment