![]() public class BGConverter : IMultiValueConverter. Then in the code I create the foreground and background converters within the namespace but outside of the window class thus: (in this case, I am reacting to the physical stock level). Here, rows background is changed using converter, where converter returns the color value. In the header part of the XAML I added: xmlns:local="clr-namespace:DataGridColrs" Then in the window.resources area I add the lines: and the code to set a default cell style thus: In my code for the datagrid, I add the line to set the cellstyle to the above. WPF DatGrid (SfDataGrid) record rows (VirtualizingCellsControl ) can be customized conditionally by changing its property value based on ‘cell value’ or ‘data object’ by using converter, where converter returns the value based on Underlying record. Where, in this example, my project (namespace) is called DataGridColrs. The alternative is to have explicitly hard-coded views for each program and sub-choice I wish to make which seems like an awful lot of duplicated code.Ĭan anyone offer any solutions? Or am I simply asking too much of the datagrids capabilities?Īs I now use this a lot, I thought I'd share what we did as I know how frustrating it is trying to locate this information. On the face of it, it seems as if this should be possible, but so far I have had no success in finding any similar examples on the web despite many house of searching. This would allow the one view to cater for any number of queries on data under one common set of functions. For that reason, I couldn't 'hard-code' date converters as I wouldn't know which column they belonged to. if the contained a specific substring).Īs I wouldn't know the name of the column and it's type at design time, I'd need to be able to react to the type at runtime which the above seems to do. Other text fields would just have their justification and background changed based on a given condition (e.g. The reason is, I am trying to create a 'generic' WPF Datagrid which reacts to the data it is displaying, the colour of numeric fields will reflect their value is a red, yellow, green for various hard-set values similar to the above code.Ī date field would want to be shown in shortdate format and it's background would need to change based on how many years away from todays date it was. ![]() This may seem like a daft question, but is it possible to use something similar so that even if you don't know the column name, you can affect the background & display of any cell in the datagrid?
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |