data bind isValid property in WPF.

data bind isValid property in WPF.

Old forum URL: forums.lhotka.net/forums/t/4997.aspx


longbridge posted on Friday, June 20, 2008

My program has a treeview for navigation. The tag property of each node (TreeViewItem) is set to a instance of business class. The business class has a boolean "IsValid" property to indicate if the data in the business class is valid or not.

We want to have a warning icon for each node to indicate the validity status of the data. So when the validity of data changes, the warning icon will show/hide.

What I did is to bind the Tag property to the Visibility of Warning image, and use a converter to read isValid attribute, convert it to  correct Visibility Type and return.

 The porblem is that when IsValid property of business class changes, the tag (instance of business class) doesn't change as well. So the warningIcon will not be udpated.

Any ideas to make this work? Is it possible to bind to the isValid property directly? Thanks.

Following are the databinding and converter codes I wrote:

<Image Name="WarningIcon" Visibility="{Binding Path=Tag, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ValidityConverter}}"  Width="16" Height="16" Margin="3,0,0,0" Source="/Test;component/Resources/imges/warning.png"/>

 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            BusinessBase bo = value as BusinessBase;
            if (bo != null)
            {
                if (!bo.IsValid)
                {
                    return Visibility.Visible;
                }
            }

            return Visibility.Collapsed;

        }

  

RockfordLhotka replied on Friday, June 20, 2008

The Csla.Wpf.ObjectStatus control exists to elevate the Is___ properties to be bindable within XAML.

longbridge replied on Saturday, June 21, 2008

Thanks. That works.

Copyright (c) Marimer LLC