MVVM Binding To Property == Null

Posted by LnDCobra on Stack Overflow See other posts from Stack Overflow or by LnDCobra
Published on 2010-06-09T17:06:10Z Indexed on 2010/06/09 17:12 UTC
Read the original article Hit count: 178

Filed under:
|
|
|

I want to show some elements when a property is not null. What is the best way of achieving this?

The following is my ViewModel:

class ViewModel : ViewModelBase
{
    public Trade Trade
    {
        get { return _trade; }
        set { SetField(ref _trade, value, () => Trade); }
    } private Trade _trade;
}

ViewModelBase inherits INotifyPropertyChanged and contains SetField()

The Following is the Trade class:

public class Trade : INotifyPropertyChaged
{
    public virtual Company Company
    {
        get { return _company; }
        set { SetField(ref _company, value, () => Company); }
    } private Company _company;
    ......
}

This is part of my View.xaml

    <GroupBox Visibility="{Binding Path=Trade.Company, 
                           Converter={StaticResource boolToVisConverter}}" />

I would like this groupbox to show only if Trade.Company is not null (so when a user selects a company). Would I need to create a custom converter to check for null and return the correct visibility or is there one in .NET?

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf