【发布时间】:2014-08-19 09:09:13
【问题描述】:
我正在开发一个Windows 8.1 apps,
我正在关注MVVM Pattern
我在应用程序中有一个网格
<Grid Name="g1">
其中需要添加一个现有的用户控件。
<UserControl
x:Class="CaptureApp.UIComponents.PlayVideo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CaptureApp.UIComponents"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid>
<MediaElement Name="MediaPlay" >
</MediaElement>
</Grid>
</UserControl>
Since View (XAML) is not allowed to know the Control.
实现它的正确方法是什么??
【问题讨论】:
-
我不明白你的问题。是什么阻止您在
中声明您的用户控件? -
是的,我可以在网格中添加用户控件并处理它在 mvvm 中的可见性,但是当应用程序启动时,用户控件将与主应用程序一起加载。我是否要在单击按钮上创建用户控件的新实例。
-
试试看rachel53461.wordpress.com/2011/05/28/…。它应该让您了解如何正确使用它。
标签: c# xaml mvvm windows-store-apps