Hi
I am creating the fields of my xam datagrid dynamically. I want to set the visibility of the unbound field using multibinding. Can you please point me in the right direction?
I am pasting my current working xaml with the relevant xaml in bold as well as the partial code that i did to implement the same using code behind.
<igDP:XamDataGrid Name="HotBucketsGrid" Theme="Office2k7Black" Background="Transparent" AutoFit="true" Style="{DynamicResource PerformantGrid}" GroupByAreaLocation="None" DataSource="{Binding HotBuckets}"> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout IsDefault="True">
<igDP:FieldLayout.Fields> <igDP:UnboundField Row="0" Column="4" Name="OrderCount" BindingPath="OrderCountUtilization" Label="OrderCount[%]" Converter="{StaticResource LimitConverter}"> <igDP:Field.Settings> <igDP:FieldSettings AllowSummaries="False" CellValuePresenterStyle="{StaticResource DynamicPercentageFieldCell}" > </igDP:FieldSettings> </igDP:Field.Settings> <igDP:Field.Visibility> <MultiBinding Converter="{StaticResource LimitFieldVisibilityConverter}" ConverterParameter="OrderCountcurrValue"> <Binding Source="{StaticResource DATA_HotBucketsViewModel}" Path="." /> <Binding Source="{StaticResource DATA_HotBucketsViewModel}" Path="FieldVisibilityChanged" /> </MultiBinding> </igDP:Field.Visibility> </igDP:UnboundField>
<igDP:UnboundField Row="1" Column="2" Name="BucketId" BindingPath="ForEachDetails" Label="{x:Null}"> <igDP:Field.Settings> <igDP:FieldSettings CellContentAlignment="ValueOnly" AllowRecordFiltering ="False" AllowSummaries="False" CellValuePresenterStyle="{StaticResource ForEachDetailsFieldCellStyle}" /> </igDP:Field.Settings> </igDP:UnboundField>
</igDP:FieldLayout.Fields></igDP:FieldLayout></igDP:XamDataGrid.FieldLayouts></igDP:XamDataGrid>
Snippet of Codebehind where i create my fields dynamically and attempt to set the visibility.
IValueConverter limitConverter = new LimitValueConverter();IMultiValueConverter limitFieldVisibilityConverter = new LimitFieldVisibilityConverter();Style dynamicPercentageFieldCell = this.FindResource("DynamicPercentageFieldCell") as Style;
foreach (var checkType in AggLimitsCheckTypeMetaData.CheckTypeMetaDataList) { foreach (var level in AggLimitsCheckTypeMetaData.CheckLevels) { var field = new UnboundField { Label = string.Format("{0} [%]", checkType.CheckType), Name = checkType.CheckType, BindingPath = new PropertyPath(checkType.CheckType + "Utilization"), Converter=limitConverter, Tag = checkType.Tag, Settings = { AllowSummaries=false, CellValuePresenterStyle = dynamicPercentageFieldCell } }; var multiBinding = new MultiBinding(); multiBinding.Converter = limitFieldVisibilityConverter; multiBinding.ConverterParameter = checkType.CheckType + "currValue"; multiBinding.Bindings.Add(new Binding(".") { Source = ViewModel }); multiBinding.Bindings.Add(new Binding("FieldVisibilityChanged") { Source = ViewModel });
multiBinding.NotifyOnSourceUpdated = true;
//field.SetBinding(UnboundField.VisibilityProperty, multiBinding); //HOW DO I SET THE ABOVE CREATED MULTI BINDING FOR THE VISIBILITY FIELD ??
hotBucketFieldLayout.Fields.Insert(fieldPosition++, field); } }
Any help is greatly appreciated
Thanks
Shahin
Hello Shahin,
Thank you for posting!
I have been looking into your description and if I understand it right the multibindign is working as expected when it is set in xaml but is not applied when it is set in code behind. If that is the case you may try to use the BindingOperations.SetBinding property. Here Vlad had shared a code snippet using IValueConverter: http://es.infragistics.com/community/forums/t/31794.aspx. The same approach could be used with a multivalueconverter. Please feel free to let me know if this helps you.
Your solution worked perfectly.
Thanks much
Thank you very much for your feedback Shahin! I am glad that the multibinding is working as expected now and I believe other community members may benefit from this as well.