How does "Binding" knows which object I want (Xaml, DataGridTextColumn) -
sorry unclear question: didn't know how write wanted ask, code helps me clear it:
vehiclewidget.xaml
<local:parkingwidget x:class="vehicleswidget" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:widgets" loaded="parkingwidget_loaded" mc:ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" height="65" width="420"> <grid height="61" width="411"> <grid.columndefinitions> <columndefinition width="5"/> <!--0--> <columndefinition width="auto"/> <!--1--> <columndefinition width="auto"/> <!--2--> <columndefinition width="298"/> <columndefinition width="0*" /> <columndefinition width="38*" /> <!--3--> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="5"/> <!--0--> <rowdefinition height="auto"/> <!--1--> <rowdefinition height="5"/> <!--2--> <rowdefinition height="auto"/> <!--3--> <rowdefinition height="5"/> <!--4--> </grid.rowdefinitions> <label content="vehicles" grid.column="1" grid.row="1"/> <button name="btnrefresh" grid.column="2" grid.row="1" content="refresh" width="98" horizontalalignment="right" click="btnrefresh_click" grid.columnspan="2" margin="0,2,257,2"> </button> <datagrid name="vehiclesdatagrid" autogeneratecolumns="false" isreadonly="true" grid.column="1" grid.row="3" grid.columnspan="3" fontfamily="arial" margin="0,0,3,0"> <datagrid.columns> <datagridtextcolumn header="time" x:name="timecolumn" binding="{binding path=time}" /> <datagridtextcolumn header="ticketid" x:name="tickedidcolumn" binding="{binding path=ticketid}" /> <datagridtextcolumn header="lpn" x:name="lpncolumn" binding="{binding path=lpn}" visibility="hidden" /> <datagridhyperlinkcolumn header="picture" x:name="picturecolumn" binding="{binding path=ticketid}" visibility="hidden"> <datagridhyperlinkcolumn.elementstyle> <style> <eventsetter event="hyperlink.click" handler="hyperlink_click"/> </style> </datagridhyperlinkcolumn.elementstyle> </datagridhyperlinkcolumn> <datagridtextcolumn header="class" x:name="classcolumn" binding="{binding path=heightclassification}" /> <datagridtextcolumn header="weight" x:name="weightcolumn" binding="{binding path=weight}" /> <datagridtextcolumn header="orientation" x:name="orientationcolumn" binding="{binding path=orientation.degrees}" /> <datagridtextcolumn header="piston1" x:name="piston1column" binding="{binding path=piston1}" /> <datagridtextcolumn header="piston2" x:name="piston2column" binding="{binding path=piston2}" /> <datagridtextcolumn header="location" x:name="locationcolumn" binding="{binding path=location}" /> </datagrid.columns> </datagrid> </grid>
in "vehiclewidget.xaml.cs" have "list vehicles", , in "vehicle" class have properties of: piston1, piston2, size, lpn , of course weight
the follows line, add column grid , names "weight" , bind weight.
<datagridtextcolumn header="weight" x:name="weightcolumn" binding="{binding path=weight}" />
how binding knows choose object, takes it's properties?
i ask question because want bind property of different object (not vehicle, in example, newvehicle, inherited vehicle).
bindings in xaml "link" between variable or object , xaml widget textview, gridviews etc. there lot of ways use it. give few examples:
-1- property sourcecode binded textblock. when variable changes value, textblock becomes updated:
<textblock text="{binding someproperty}"/>
-2- more complicated example, textbox's value becomes updated if variable changes , variable becomes updated when value of textbox changed:
<textblock text="{binding somevar, mode=twoway}"/>
-3- databinding converter, means can write converter in c# processes binded value , returns custom value/object:
xaml
<textblock text="trafficlight" background="{binding trafficlightstate, converter={staticressource trafficlightstatetocolorconverter}}">
c#
public class trafficlightstatetocolorconverter : ivalueconverter { public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { if(value.equals("green")) return color.fromknowncolor(knowncolor.green) else if(value.equals("yellow")) return color.fromknowncolor(knowncolor.yellow) else return color.fromknowncolor(knowncolor.red) } }
does answer questions, how xaml knows object has used?
Comments
Post a Comment