Hi
Please consider the following:
<igDP:Field Name="Name" Label="{Binding Path=ModeAlt, Mode=OneWay, PresentationTraceSources.TraceLevel=High}">
<igDP:Field.Settings>
<igDP:FieldSettings AllowEdit="False" AllowGroupBy="False" AllowResize="True" CellClickAction="SelectRecord" />
</igDP:Field.Settings>
</igDP:Field>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
When the above code is used, I get a binding error in me immediates window saying:
Cannot find governing FrameworkElement or FrameworkContentElement for target element
Has anyone successfully bound a DtaPresenter Field.Label to a dependency property?
Thanks
PS.. this forum is still nasty as anything for pasting code... so much for pleasent user experiences! :o)
Fields are not part of the visual tree of the XamDataGrid so you cannot bind their properties. However, you can see how to go around this here:
http://blogs.infragistics.com/blogs/josh_smith/archive/2008/06/06/binding-a-xamdatagrid-field-property.aspx
That's fine for when you are creating a viewmodel within the user interface constructor, but if the datacontext is null at that point, how do you change a grids column label text dynamically/programmatically? (it does not necessarily have to be via binding)
<igDP:Field Name="CodeName" Label="Code" Width="Auto" />
I want the text in the label to be dynamic depending on a value in the viewmodel ("xxx Code")
Sorry for the double post but the code didn't format in the last
post...
private void UpdateLabels() { Infragistics.Windows.Utilities.GetDescendantFromType
<LabelPresenter>(AllocationsGrid, false, new
Infragistics.Windows.Utilities
.DependencyObjectSearchCallback
<LabelPresenter>(DescendentCallback)); } private bool DescendentCallback(LabelPresenter target) { TextBlock textBlock = Infragistics.Windows.Utilities.
GetDescendantFromType(target, typeof(TextBlock), false)
as TextBlock; if (textBlock != null) { //get the labelPresenter you want to modify
based on a unique
value (you could set the Tag property in xaml). if (target.Tag == "SomeUniqueProperty") { //set the label to whatever you want here textBlock.Text = "New Label Name"; //breaks the descendent callback recursion return true; } } return false; } private void MyGrid_LayoutUpdated(object sender, EventArgs e) { UpdateLabels(); } private void MyPage_Loaded() { UpdateLabels(); }
You can access the TextBlock inside the LabelPresenter and modify it using code with the example below. In my opinion this is a terrible hack, but as an earlier post states the grid was not architected for binding because the fields don't exist in the visual tree. Hope this helps.
private void UpdateLabels() {
Infragistics.Windows.Utilities.GetDescendantFromType<LabelPresenter>(AllocationsGrid, false, new Infragistics.Windows.Utilities.DependencyObjectSearchCallback<LabelPresenter>(DescendentCallback)); }
private bool DescendentCallback(LabelPresenter target) { TextBlock textBlock = Infragistics.Windows.Utilities.GetDescendantFromType(target, typeof(TextBlock), false) as TextBlock; if (textBlock != null) { //get the labelPresenter you want to modify based on a unique value (you could set the Tag property in xaml). if (target.Tag == "SomeUniqueProperty") { textBlock.Text = "New Label Name"; return true; //breaks the descendent callback recursion } } return false; } You may also need to hook into the grids "LayoutUpdated" event and also call your UpdateLabels() method so the grid won't overwrite your changes.private void MyGrid_LayoutUpdated(object sender, EventArgs e) { UpdateLabels(); }
private bool DescendentCallback(LabelPresenter target) { TextBlock textBlock = Infragistics.Windows.Utilities.GetDescendantFromType(target, typeof(TextBlock), false) as TextBlock; if (textBlock != null) { //get the labelPresenter you want to modify based on a unique value (you could set the Tag property in xaml).
if (target.Tag == "SomeUniqueProperty") { textBlock.Text = "New Label Name";
return true; //breaks the descendent callback recursion
}
return false;
You may also need to hook into the grids "LayoutUpdated" event and also call your UpdateLabels() method so the grid won't overwrite your changes.private void MyGrid_LayoutUpdated(object sender, EventArgs e)
You may also need to hook into the grids "LayoutUpdated" event and also call your UpdateLabels() method so the grid won't overwrite your changes.
private void MyGrid_LayoutUpdated(object sender, EventArgs e)
{ UpdateLabels(); }