我的第一个控制器--ViewController
class ViewController: UIViewController,testProtocol {
@IBAction func btInit(sender: AnyObject) {
println("Bt Init")
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initViewController: UIViewController = storyBoard.instantiateViewControllerWithIdentifier("viewTarget") as targetViewController
self.presentViewController(initViewController,animated: false, nil)
}
var targetController = targetViewController();
override func viewDidLoad() {
super.viewDidLoad()
self.targetController.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func testDelegate(){
println(" in my view controller delegate ")
}
}
Run Code Online (Sandbox Code Playgroud)
在我的第二个视图控制器 - targetViewController
protocol testProtocol {
func testDelegate() …Run Code Online (Sandbox Code Playgroud) 我决定使用MVVM Light库来帮助设计UI.经过大量的研究和反复试验,我还没有找到我想要的答案.我用谷歌搜索并阅读了我能找到的每个StackOverflow问题,然而,我的问题似乎在SO上是独一无二的.
我希望设计一个带有单个窗口的UI,并使用不同的Views/UserControls填充它.我不想在UserControls中使用共享导航栏,也不想弹出多个窗口.每个View/UserControl都应绑定到自己的ViewModel,而MainWindow将绑定到MainViewModel.
示例场景 - 具有3个UserControl的MainWindow
1. MainWindow populates with first UserControl which has a listbox and 3 buttons, the first button is enabled.
2. User clicks the first button.
3. MainWindow populates with second UserControl.
Run Code Online (Sandbox Code Playgroud)
或者,另外
2. User selects choice from a listbox, button two and three become available.
3. User clicks second/third button.
4. MainWindow populates with second/third UserControl.
Run Code Online (Sandbox Code Playgroud)
等等
也许我的方法不现实,但我觉得这必须是可能的.我不明白如何让所有这些作品在概念上发挥作用.我的欲望绝不是独一无二的.如果您认为这是重复的问题,请重定向.干杯.
为了使事情更容易理解,我在下面列出了一些课程.首先,我的App.xaml.
<Application x:Class="Bobcat_BETA.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="clr-namespace:Bobcat_BETA.UserControls"
xmlns:vm="clr-namespace:Bobcat_BETA.ViewModels"
StartupUri="MainWindow.xaml"
mc:Ignorable="d">
<Application.Resources>
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
<DataTemplate …Run Code Online (Sandbox Code Playgroud)