c# - WPF Design Time Data and Data Templates -


i'm developing wpf user control , want display design-time data. it's proving quite challenge things right , use help.

here's control far, <listbox>:

<usercontrol x:class="ta.weather.ui.wpf.workingseteditor"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"              mc:ignorable="d"               d:designheight="300" d:designwidth="300"              loaded="handleloadedevent"              >     <grid d:datacontext="{d:designdata source=/sampledata/workingset.xaml}">         <listbox x:name="workingsetlistbox"  >             <grid>                 <grid.columndefinitions>                     <columndefinition minwidth="30" />                     <columndefinition minwidth="30" />                     <columndefinition minwidth="30" />                     <columndefinition minwidth="30" />                     <columndefinition minwidth="30" />                     <columndefinition />                 </grid.columndefinitions>                 <textblock grid.column="0" textalignment="center"                            text="{binding path=[0].limits.stationid}"></textblock>                 <textblock grid.column="1" textalignment="center"                            text="{binding path=[0].limits.sensorid}"></textblock>                 <textblock grid.column="2" textalignment="center"                            text="{binding path=[0].limits.sensorname}"></textblock>                 <textblock grid.column="3" textalignment="center"                            text="{binding path=[0].limits.lowerlimit}"></textblock>                 <textblock grid.column="4" textalignment="center"                            text="{binding path=[0].limits.upperlimit}"></textblock>                 <checkbox grid.column="5" x:name="monitoredcheckbox"                           ischecked="{binding path=[1].monitored}"/>             </grid>         </listbox>     </grid> </usercontrol> 

i figured out how create design-time data in xaml file, , set build action designdatawithdesigntimecreatabletypes. type dto seems ok create instances @ design time. here's data file, containing list<sensorstate> 2 members:

<generic:list x:typearguments="ws:sensorstate"               xmlns:ws="clr-namespace:ta.weather.core;assembly=ta.weather.core"               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"               xmlns:generic="clr-namespace:system.collections.generic;assembly=mscorlib">     <ws:sensorstate idletimeout="300" lastupdate="2015-08-19t03:39:00.000z" monitored="false"                     withinacceptablelimits="false">         <ws:sensorstate.limits>             <ws:sensorlimits stationid="12-34-56-78-90-12" sensorid="1" sensorname="inside temperature"                              lowerlimit="-10" upperlimit="30" />         </ws:sensorstate.limits>     </ws:sensorstate>     <ws:sensorstate idletimeout="300" lastupdate="2015-08-19t03:39:00.000z" monitored="true"                     withinacceptablelimits="false">         <ws:sensorstate.limits>             <ws:sensorlimits stationid="12-34-56-78-90-12" sensorid="1" sensorname="inside temperature"                              lowerlimit="-10" upperlimit="30" />         </ws:sensorstate.limits>     </ws:sensorstate> </generic:list> 

thus far, gets me user control looks this: user control design-time data

so, success of sorts. however, there 2 questions @ point:

  • why 1 row show when there 2 items in list? can control which instance shows changing array index in binding expression, how rows repeat? tried removing array index gives compile error.
  • i'm getting errors against data file of form "the member xxx not recognized or not accessible", 1 each property i'm setting, 36 in total. though build succeeds , design-time data shows in editor. errors i'm sure important - have no idea compiler trying tell me. these errors mean , need mitigate them?

there's more. want use datatemplate create nicer data; bit later on there going slider control setting limits, etc. here's how i've tried use template:

<usercontrol x:class="ta.weather.ui.wpf.workingseteditor"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"              xmlns:core="clr-namespace:ta.weather.core;assembly=ta.weather.core"              mc:ignorable="d"               d:designheight="300" d:designwidth="300"              loaded="handleloadedevent"              >     <grid d:datacontext="{d:designdata source=/sampledata/workingset.xaml}">         <grid.resources>             <datatemplate x:key="workingsettemplate">                 <grid>                     <grid.columndefinitions>                         <columndefinition minwidth="30" />                         <columndefinition minwidth="30" />                         <columndefinition minwidth="30" />                         <columndefinition minwidth="30" />                         <columndefinition minwidth="30" />                         <columndefinition />                     </grid.columndefinitions>                     <textblock grid.column="0" textalignment="center"                            text="{binding path=[0].limits.stationid}"></textblock>                     <textblock grid.column="1" textalignment="center"                            text="{binding path=[0].limits.sensorid}"></textblock>                     <textblock grid.column="2" textalignment="center"                            text="{binding path=[0].limits.sensorname}"></textblock>                     <textblock grid.column="3" textalignment="center"                            text="{binding path=[0].limits.lowerlimit}"></textblock>                     <textblock grid.column="4" textalignment="center"                            text="{binding path=[0].limits.upperlimit}"></textblock>                     <checkbox grid.column="5" x:name="monitoredcheckbox"                           ischecked="{binding path=[1].monitored}"/>                 </grid>              </datatemplate>         </grid.resources>         <listbox x:name="workingsetlistbox" itemtemplate="{dynamicresource workingsettemplate}">         </listbox>     </grid> </usercontrol> 

so basically, i've moved <grid> out of <listbox> , <datatemplate> resource. this, design-time data vanishes , i'm left blank control in designer. third question becomes:

  • why design-time data vanish when use <datatemplate>? need differently?

you can tell have no experience wpf... must admit struggling binding expressions little bit, seem sort of arcane magic little rhyme or reason them. think maybe i'm missing important concept somewhere. hope can give me few wise words push me in right direction.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -