Pavan
Pavan

Reputation: 533

XMAL Binding and CollectionViewSource issue in WinRT

In my case everything is working fine accept IsBusy property, while getting data from the web service in VM (View Model) i am explicitly update the IsBusy = true to show the progress-bar on UI but it is NOT working. And propertychanged is always null. So progress-bar Visibility always Visible which is bind with IsBusy property. please help what I am missing here.

Here is my code of XAML:

    <local:StockVm x:Key="VM"/>

    <CollectionViewSource x:Key="CVS" Source="{Binding RequestedItems, Source={StaticResource VM}}"
                          IsSourceGrouped="True"
                          ItemsPath="StockItems"/>      

</Page.Resources>

Page Design XAML code:

 <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <TextBlock Grid.Row="0"  Visibility="{Binding Path=IsBusy, Converter={StaticResource boolVis1}, ConverterParameter=true}">Loading...</TextBlock>
    <ProgressBar x:Name="LoadingBar" Visibility="{Binding Path=IsBusy, Converter={StaticResource boolVis1}, ConverterParameter=true}" IsIndeterminate="true" Height="4"  />

    <local:DebugListView x:Name="TheListView" Grid.Row="1" ItemsSource="{Binding Source={StaticResource CVS}}" ItemTemplate="{StaticResource ItemTemplate}" >
        <ListView.GroupStyle>
            <GroupStyle HeaderTemplate="{StaticResource StockHeaderTemplate}" HeaderContainerStyle="{StaticResource ListViewHeaderItemStyle}" />
        </ListView.GroupStyle>
    </local:DebugListView>

</Grid>

.CS Code

 public TestPageDev()
        {
            this.InitializeComponent();
            _view = this.Resources["VM"] as StockVm;
            _view.LoadData();    
            this.DataContext = this; 
        }

public class StockVm : BindableObject { private ObservableCollection _requestedItems;

    public ObservableCollection<RequestedStock> RequestedItems
    {
        get { return _requestedItems; }
        set { SetProperty(ref _requestedItems, value); }
    }

    public StockVm()
    {

    }

    public async Task LoadData()
    {
        IsBusy = true;
        await Task.Delay(TimeSpan.FromSeconds(5));
        IsBusy = false;
    }


    #region - Public Members -
    private bool _IsBusy = false;
    public bool IsBusy
    {
        get
        {
            return _IsBusy;
        }
        set
        {
            if (_IsBusy != value)
            {
                _IsBusy = value;
                RaisePropertyEvent("IsBusy");
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    #endregion

    #region - INotifyPropertyChanged -

    private void RaisePropertyEvent(string propName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propName));
    }
    #endregion

}

Upvotes: 0

Views: 78

Answers (1)

Clemens
Clemens

Reputation: 128061

You would have to set the DataContext to the view model instance, like this:

public TestPageDev()
{
    this.InitializeComponent();
    _view = this.Resources["VM"] as StockVm;
    _view.LoadData();    
    this.DataContext = _view; // here
}

(where _view is quite a strange name for a view model object).

Or you explicitly set the binding source like this:

Visibility="{Binding Path=IsBusy, Source={StaticResource VM}, ...}"

Upvotes: 1

Related Questions