简体   繁体   中英

MVVM+ WPF PopUp not opening

XAML

<Popup Name="popUpProgress" Width="225" Height="85"                   
           IsOpen="{Binding PopUpIsOpen,Mode=OneWay}"
           Placement="Center" PlacementTarget="{Binding ElementName=stkListview}" 
           VerticalAlignment="Top">
    <Border BorderThickness="1" Background="Blue"  >
        <Grid   Width="225" Height="85">
            <Grid.RowDefinitions>
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
            </Grid.RowDefinitions>
            <Label x:Name="lblProgress" Content="Please Wait ...." Margin="10,5,0,0" HorizontalAlignment="Left" Grid.Row="1" />
        </Grid>
    </Border>
</Popup>

In view Model:

private bool _PopUpIsOpen;

public bool PopUpIsOpen
{
    get { return _PopUpIsOpen; }
    set
    {
        _PopUpIsOpen = value;
        RaisePropertyChanged(() => this.PopUpIsOpen);
    }
}

public RelayCommand SubmitCommand { get; private set; }

private bool SubmitCommandCanExecute()
{
    return true;
}

private void SubmitCommandExecute()
{

    PopUpIsOpen = true;

    dsStandardListbyMarket = marketBL.StandardListbyMarketBL(Convert.ToInt32(SelectdMarketId), Convert.ToInt32(Users.UserId));
    GetComboboxMappingCollections(Convert.ToInt32(this.SelectdMarketId), Users.UserId);
    FItems = new ObservableCollection<MarketRecord.FItem>();
    FItems.CollectionChanged += OnUICollectionChanged;
    marketBL.FetchMarketRecords(Convert.ToInt32(this.SelectdMarketId));
    IsSubmitButtonVisible = true;

    PopUpIsOpen = false;
}

When I click on submit button control comes to SubmitCommandExecute but Popup window is not showing. I am bit new to WPF, scratching my head over it. Finally raising this question here. What might be wrong.

I think the problem is in the way you are testing the code. SInce you are sleeping in the UI thread, the UI does not feel the change from true to false on the bound property. Try to use a timer instead of a Sleep in the thread.

Given the RaisePropertyChanged syntaxe on msdn :

protected internal void RaisePropertyChanged (
   string propertyName
)

You should try RaisePropertyChanged("PopUpIsOpen"); instead of RaisePropertyChanged(() => this.PopUpIsOpen);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM