2015-11-24 18 views
0

我想在用戶在不同視圖之間移動時總是在屏幕上可見的視圖中顯示一個加載器。 頁腳我添加了加載程序,並且我會通過變量出現並通過實例化的模型消失。 但它不起作用。在調試模型中正確地模擬true/false值的模型,但不考慮頁腳。一些幫助 ?還是按事件?這是可能的 ?在MVVM模式的WPF中的不同視圖中設置變量

頁腳XAML

<StackPanel DataContext="{StaticResource vmp}" Orientation="Horizontal" DockPanel.Dock="Bottom" Height="40" Background="#eeeeee"> 
      <ContentControl prism:RegionManager.RegionName="FooterRegion" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> 

      <TextBlock Text="eStart Enterprise 2.13.15" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="12" Margin="25,0,0,0"></TextBlock> 
      <!-- my loader is progressbar here, default is false --> 
      <ProgressBar Width="200" Margin="885, 0, 0, 0" Visibility="{Binding Path=model.Loader, Mode=TwoWay, Converter={StaticResource booleanToVisibilityConverter}}" HorizontalAlignment="Right" VerticalAlignment="Center" IsIndeterminate="True" Value="100" /> 
     </StackPanel> 

myViewModel.cs(我會打電話視圖模型到另一個XAML變量設置真正的進度 ):

class ReadAndPrintFromDevice : ICommand 
      { 

       public event EventHandler CanExecuteChanged; 

       public bool CanExecute(object parameter) 
       { 
        return true; 
       } 

       public async void Execute(object parameter) 
       { 
        //this don't work 
        modelViewModel.getInstance().Loader = true; 
        //other code 
       } 
} 

我該如何解決,讓所有我總是在該變量上查看加載器還是加載器?

回答

0

您使用棱鏡,因此您可以使用IEventAggregator。

事件

public class ChangeLoaderEventDataModel 
{ 
} 

創建活動

public class ChangeLoaderEvent: PubSubEvent<ChangeLoaderEventDataModel> 
{ 
} 

下一個事件的控制,其中包括裝載機

_eventAggregator.GetEvent<ChangeLoaderEvent>().Subscribe(ShowLoaderMethod); 

之後,你可以觸發事件在何時何地訂閱創建的DataModel你需要它

_eventAggregator.GetEvent<ChangeLoaderEvent>().Publish(new ChangeLoaderEventDataModel()); 
+0

謝謝!那是行得通的 –