2014-10-07 72 views
0

我有3个区域,分别是菜单,工具栏和内容。当在菜单视图中单击一个模块(即客户)时,它将在编辑文本框中的值之后导航到内容区域中的相应视图,我需要将其保存到数据库。在工具栏视图中单击保存按钮时如何获取活动视图的底层视图模型并发送到DAL? Shell.xaml:如何从WPF Prism中的另一个视图获取视图/区域的底层视图模型

<Grid DockPanel.Dock="Left" Width="65" Margin="1"> 
     <Border CornerRadius="1" BorderBrush="Black" BorderThickness="1"> 
      <StackPanel Orientation="Vertical" Margin="1" > 
       <ContentControl Name="menuControl" PrismRegions:RegionManager.RegionName="{x:Static infra:RegionNames.MenuRegion}"/> 
      </StackPanel> 
     </Border> 
    </Grid> 
    <Grid DockPanel.Dock="Top" Margin="1"> 
     <Border CornerRadius="1" BorderBrush="Black" BorderThickness="1" > 
      <StackPanel Orientation="Vertical" Margin="2"> 
       <ContentControl Name="toolbarControl" PrismRegions:RegionManager.RegionName="{x:Static infra:RegionNames.ToolbarRegion}"/> 
      </StackPanel> 
     </Border> 
    </Grid> 
    <Grid DockPanel.Dock="Right" Margin="2"> 
     <Border CornerRadius="1" BorderBrush="Black" BorderThickness="1"> 
    <StackPanel Margin="5" > 
      <ContentControl Name="contentControl" DockPanel.Dock="Top" PrismRegions:RegionManager.RegionName="{x:Static infra:RegionNames.ContentRegion}"/> 
    </StackPanel> 
     </Border> 
    </Grid> 

Menu.xaml:

<Button Grid.Row="0" Name="btnHome" Background="Transparent" Margin="1" ToolTip="Home" Command="{x:Static inf:ApplicationCommands.NavigationCommand}" CommandParameter="{x:Type mod:HomeView}"> 
     <TextBlock Height="32" Width="32" Text =""> 
      <TextBlock.Background> 
       <ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/home_32.png"/> 
      </TextBlock.Background> 
     </TextBlock> 
    </Button> 
    <Button Grid.Row="1" Name="btnBank" Background="Transparent" Margin="1" ToolTip="Bank" Command="{x:Static inf:ApplicationCommands.NavigationCommand}" CommandParameter="{x:Type mod:BankView}"> 
     <TextBlock Height="32" Width="32" Text =""> 
      <TextBlock.Background> 
       <ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/bank_64.png"/> 
      </TextBlock.Background> 
     </TextBlock> 
    </Button> 
    <Button Grid.Row="2" Name="btnCustomer" Background="Transparent" Margin="1" ToolTip="Customer" Command="{x:Static inf:ApplicationCommands.NavigationCommand}" CommandParameter="{x:Type mod:CustomerView}"> 
    <TextBlock Height="32" Width="32" Text =""> 
     <TextBlock.Background> 
       <ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/customer_128.ico"/> 
     </TextBlock.Background> 
    </TextBlock> 
    </Button> 
    <Button Grid.Row="3" Name="btnEmployee" Background="Transparent" Margin="1" ToolTip="Employee" Command="{x:Static inf:ApplicationCommands.NavigationCommand}" CommandParameter="{x:Type mod:EmployeeView}"> 
    <TextBlock Height="32" Width="32" Text =""> 
     <TextBlock.Background> 
       <ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/employee_128.png"/> 
     </TextBlock.Background> 
    </TextBlock> 
    </Button> 

Toolbar.xaml:

<Button Grid.Column="0" Margin="1" Name="btnAdd" Height="35" Width="35" ToolTip="Add" Background="Transparent" Command="{Binding AddCommand}" CommandParameter="Add" > 
      <TextBlock Height="30" Width="30" Text =""> 
       <TextBlock.Background> 
       <ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/plus_32.png"/> 
       </TextBlock.Background> 
      </TextBlock> 
     </Button> 
    <Button Grid.Column="1" Margin="1" Name="btnEdit" Height="35" Width="35" ToolTip="Edit" Background="Transparent" Command="{Binding EditCommand}" CommandParameter="Edit" > 
      <TextBlock Height="30" Width="30" Text =""> 
       <TextBlock.Background> 
        <ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/pencil_32.png"/> 
       </TextBlock.Background> 
      </TextBlock> 
     </Button> 
    <Button Grid.Column="2" Margin="1" Name="btnSave" Height="35" Width="35" ToolTip="Save" Background="Transparent" Command="{Binding SaveCommand}" CommandParameter="Save" > 
      <TextBlock Height="30" Width="30" Text =""> 
       <TextBlock.Background> 
        <ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/save_32.png"/> 
       </TextBlock.Background> 
      </TextBlock> 
     </Button> 
    <Button Grid.Column="3" Margin="1" Name="btnPrint" Height="35" Width="35" ToolTip="Print" Background="Transparent" Command="{Binding PrintCommand}" CommandParameter="Print" > 
      <TextBlock Height="30" Width="30" Text =""> 
       <TextBlock.Background> 
        <ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/print_32.png"/> 
       </TextBlock.Background> 
      </TextBlock> 
     </Button> 

UI设计:

Attached the Image

+0

你可以发布你的内容区域视图代码和视图模型代码。 – WPFKK 2014-10-07 19:00:19

回答

0

基本上ÿ我们的观点的状态完全存在于视图模型中。在您的按钮被淘汰侧形式的视图模型来拯救你可以做什么的情形是:

在工具栏视图模型: 提高该保存按钮被点击

myEventAggregator.RaiseEvent<SaveButtonClicked>().Publish(args); 

在视图模型构造的事件: 认购,你提高的情况下,当你在栏区域

myEventAggregator.GetEvent<SaveButtonClicked>().Subscribe(yourSubscriberDelegate); 

点击保存按钮在窗体上的退出或形式的取消:取消 的事件。 (这样可以确保不会有多个活动形式的同时节省了数据)

myEventAggregator.GetEvent<SaveButtonClicked>().UnSubscribe(yourSubscriberDelegate); 

为此,您需要发布和订阅的事件聚合知识。查找更多详情here