2014-10-07 76 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

相關問題