开发者

Using converters for DataGrid Column

开发者 https://www.devze.com 2023-01-20 18:10 出处:网络
I create开发者_如何转开发 my windows databainding infrastructure with MVVM pattern. I have method which return data for my DataGrid. Problem thatI want some columns in DataGrid use Converter (IValueCo

I create开发者_如何转开发 my windows databainding infrastructure with MVVM pattern. I have method which return data for my DataGrid. Problem that I want some columns in DataGrid use Converter (IValueConverter) but I bind my DataGrid to the data directly. I can't strongly type columns specification in xaml because number of columns can be different. Also I can't get UI element (DataGrid) in ViewModel for change.


Your ViewModel can expose the column collection (structure which can specify column header, type of data, necessary information to use converter) bind that to a DP of your view and your view needs to add the columns to the datagrid after parsing that and preparing datatemplate for datagrid column's cell template and cell edittemplate which specifies the binding source, converter.

0

精彩评论

暂无评论...
验证码 换一张
取 消