Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
295
Set Visibility of Unbound Field from codebehind using MultiBinding
posted

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