data binding - WPF Generic DataGrid CellTemplate - Bind to Cell Value? -
After
I'm having some problem understanding the basics of data binding in WPF. I have a generic datagrid (with Autogenerate column set) which is bound to datatable with the names of columns which varies on every load. When DataTable columns are of that type of boolean, I want to have a column that represents the custom images to be true and false.
The completion of I announced on page one StaticResource celltemplate, and I entrap C # code that AutoGenerateColumn event and use this template:
& lt; DataTemplate x: key = "CheckmarkColumnTemplate" & gt; & Lt; Image X: name = "CheckmarkImage" source = ".. \ .. images \ check.png" height = "16" width = "16" /> & Lt; DataTemplate.Triggers & gt; & Lt; DataTrigger Binding = "{Binding RelativeSource = {RelativeSource TemplatedParent}, Path = Value}" Value = "false" & gt; & Lt; Setter target name = "checkmark image" property = "source" value = ".. \ .. \ images \ nocheck.png" /> & Lt; / DataTrigger & gt; & Lt; /DataTemplate.Triggers> & Lt; / DataTemplate & gt; C # code:
private void dgData_AutoGeneratingColumn (object sender, DataGridAutoGeneratingColumnEventArgs e) {if (e.PropertyType == typeof (bool)) {DataGridTemplateColumn Col = new datagrid template column (); Binding binding = new binding (e. Property name); Col.CellTemplate = (this.Resources ["CheckmarkColumnTemplate"] as DataTemplate); Col.Header = e.PropertyName; E.Column = col; }} It mostly works, but I have Datatrigr binding properties mess I value in the column "false", it never does not know why it nocheck.png image Never shows up I do not know how compelling asset write, so keep to be referred to Detabend column values (remember, the column name is different every time, so I can not column name hard-coded in part by binding path ).
Can anyone tell me what the binding property should look like to catch the value of the column?
I have a single problem and still looking for an answer. My current solution is DataTemplate to create AutoGeneratingColumn event handler, so
Private Zero onAutoGeneratingColumn (Object Sender, DataGridAutoGeneratingColumnEventArgsE) {e.Column = New DataGridTemplateColumn {Header = E. Property Name, Seltamplet = Bnaaasimlkeltemplet (e.PropertyName)}} private static Detatamplet Bnaaasimlkeltamplet (String Property name) {Detataimlet template = new Detatamplet (); Template. VisualTrue = New Framework Element Faster (typef (label)); Template. Visual Studio. Setting (contentproperty, new binding (property name)); Return template; }
Comments
Post a Comment