Hello, does anybody know how to programatically access and modify template objects inside fields of XamDataGrid?
I got a combobox in Field 1 which will judge which values to show in combobox Field 2. I want to do this programatically, as the values
of Field 2 needs to be calculated first. I would like to use XamTextEditor or similar for the combobox as a template. Is it possible to use FindName function to access the combobox objects inside the template in XamDataGrid like in WPF?
Could I get a program example or a XAML sample for how to communicate and fetch between two objects in two fields in XamDataGrid?
Thanks,
Tore, Norway
I Found a solution.... Thanks for all your help.
if i dynamically create the Style in code (instead of using the resource) I can accomplish what I am needing to do...
string sStyleTemplate = "<Style xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:igDP=\"http://infragistics.com/DataPresenter\" xmlns:tss=\"clr-namespace:Newmont.TSS.Studio.ParmsUIControl;assembly=StudioUtilities\" xmlns:ParmsUI=\"clr-namespace:Newmont.TSS.Studio.ParmsUIControl;assembly=StudioUtilities\" TargetType=\"{x:Type igDP:CellValuePresenter}\"><Setter Property=\"Template\"><Setter.Value><ControlTemplate TargetType=\"{x:Type igDP:CellValuePresenter}\"> <tss:TSSFileSelectorControl FileName=\"{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=TwoWay}\" ApplicationHost=\"{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ParmsUI:ParmUIManager}}, Path=HostInterface, Mode=OneWay}\" /></ControlTemplate></Setter.Value></Setter></Style>";
<<<<--- modify whatever part of the string we need to modify -->>>
StringReader stringReader = new StringReader(sStyleTemplate);System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stringReader);Style foo1 = (Style)XamlReader.Load(xmlReader); newField.Settings.CellValuePresenterStyle = foo1;
Yes - I was trying the descendant methods... But the problem is, I do not have any visual elements at the time I am setting the style - I am trying to do this when I am creating the field in the grid (See my previous comments).
We have a dynamic UI that is created from specifications, the specifications state what attributes the fields have - these specification are read, and datagrid fields are created - for a few 'types' we use user controls, and those usercontrols have properties that need to be set at this time. Once the fields are created in the datagrid, we no longer have access to the specification data. This all happens well before row data is added to the grid,
The Get...Fromtype and Get...Fromname require a visual element (Like cell) in order to work - I dont have that.
Rod
In this case you should use GetDescendantFromType method, because you are trying to go down the element tree. You can pass the CellValuePresenter as the source descendant
CellValuePresenter cvp = CellValuePresenter.FromCell(...);
Test this and let me know if it works in your scenario.
Alex.
Please note: I am trying to do this when I am programatically creating the fields (and i only need to do it once). I dont have any visual elements yet.
most of the information I have found relates to doing this when visual elements exist.
I have tried that with no success... It always comes back null... I need this because in the cellvaluepresenterstyle, I am using a user object. This user object has dependency properties that need to be set based on values else where in the system. With my current model, i can set these values only in the resources, not in my code when I create the field. here is my code
UnboundField newField = new UnboundField();newField.DataType = typeof(string);newField.Settings.CellValuePresenterStyle = this.rootPanel.parentParmManager.Resources["FileSelectorStyle"] as Style;
// This returns null
TSSFileSelectorControl crp = Infragistics.Windows.Utilities.GetAncestorFromType(newField, typeof(TSSFileSelectorControl), true) as TSSFileSelectorControl;
<Style x:Key="FileSelectorStyle" TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <tss:TSSFileSelectorControl x:Name="GridFileSelector" FileName="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=TwoWay}" ApplicationHost="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ParmsUI:ParmUIManager}}, Path=HostInterface, Mode=OneWay}" /> </ControlTemplate> </Setter.Value> </Setter> </Style>