Prism 和 AnimatedTabControl
我很想使用它,但我无法弄清楚如何将项目绑定到它。
我想看一个简单的例子,比如
Shell.xaml
<Controls:AnimatedTabControl
x:Name="TestTab"
SelectedIndex="0"
VerticalAlignment="Stretch"
cal:RegionManager.RegionName="{x:Static inf:RegionNames.TestRegion}"
Grid.Row="1"
/>
--
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
namespace HelloWorldModule
{
public class HelloWorldModule : IModule
{
private readonly IRegionManager regionManager;
public HelloWorldModule(IRegionManager regionManager)
{
this.regionManager = regionManager;
}
public void Initialize()
{
regionManager.RegisterViewWithRegion(
RegionNames.SecondaryRegion, typeof(Views.HelloWorldView));
regionManager.RegisterViewWithRegion(
RegionNames.TestRegion, typeof(Views.TestTab));
}
}
}
需要哪些代码才能拥有多个选项卡,这些选项卡在 TestRegion
中的更改时显示动画。 我似乎无法弄清楚如何将任何内容绑定到 AnimatedTabControl 甚至常规选项卡控件...
I would love to use this, but cannot for the life of me figure out how to bind items to it.
I would like to see a simple example, something like
Shell.xaml
<Controls:AnimatedTabControl
x:Name="TestTab"
SelectedIndex="0"
VerticalAlignment="Stretch"
cal:RegionManager.RegionName="{x:Static inf:RegionNames.TestRegion}"
Grid.Row="1"
/>
--
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
namespace HelloWorldModule
{
public class HelloWorldModule : IModule
{
private readonly IRegionManager regionManager;
public HelloWorldModule(IRegionManager regionManager)
{
this.regionManager = regionManager;
}
public void Initialize()
{
regionManager.RegisterViewWithRegion(
RegionNames.SecondaryRegion, typeof(Views.HelloWorldView));
regionManager.RegisterViewWithRegion(
RegionNames.TestRegion, typeof(Views.TestTab));
}
}
}
What code is needed to have multiple tabs that animate on change in TestRegion
.
I cannot seem to figure out how to bind anything to AnimatedTabControl or even a regular tab control...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您面临的问题是,当您实际上想要使用视图注入时,您正在使用视图发现。
使用视图发现,您可以将视图注册到某个区域,并且当该区域显示时,每个视图都会动态加载。 我的猜测是,您在该区域变得可见后向该区域注册视图。 这意味着您的视图永远不会被实例化,因为该区域已经变得可见。
视图注入动态地将视图插入到已经存在的区域中。 我想这就是你想做的。 您的 shell 很好,但您需要将以下内容添加到您的 Module Initialize() 调用中:
这应该可以解决问题。
注意:您可以通过调用 IRegion 上的 Activate/Deactivate 方法来显示/隐藏某个区域中的视图,如下所示:
I think the problem you're facing is that you're using View Discovery when you actually want to use View Injection.
With View Discovery, you register views with a region and, when the region gets displayed, each of the views get dynamically loaded. My guess is that you're registering views with a region after the region has been made visible. This means that your views will never get instantiated as the Region has already been made visible.
View Injection dynamically inserts a view into an already existing region. I think this is what you want to do. Your shell is fine but you'll need to add the following to your Module Initialize() call:
This should do the trick.
NB: you can show/hide views in a region by calling the Activate/Deactivate method on the IRegion like so: