【发布时间】:2014-09-03 12:23:07
【问题描述】:
我是 C# Silverlight 初学者,我正在使用 silverlight5 和 MVVM 方法。
我必须做什么? 我已经创建了一个 xaml 假设:
<UserControl x:Class="DEV_CENTER.TabControlStuff.UIeLementRender"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
</Grid>
</UserControl>
现在我想将此网格绑定到一个 viewModel 类,该类将在其上呈现一个包含组合框的网格。该怎么做?
我尝试通过像这样更改网格来添加"{Binding UIElements}"
<Grid x:Name="LayoutRoot" Background="White" {Binding UIElements}>
当然不支持。
那么如何使用 MVVm 方法绑定此网格以在其上呈现 UIElemnts(组合框)?
编辑: 情况是我有一个网格已经包含一个组合框(使用 c# 代码动态获得)并且我想在网格上渲染该网格(这个网格是创建时获得的默认网格xaml)(通过使用 MVVM 绑定,我必须通过执行类似{Binding AlreadComboContainingGrig} 的操作将其绑定到使用 MVVM 的此 xaml degault 创建的网格来渲染先前获得的网格(使用 c#,包含组合框)。
而我要绑定的 ViewModel 类看起来像这样:
public class uiElementRendererViewModel : GenericViewModel
{
private Grid alreadComboContainingGrig;
public Grid AlreadComboContainingGrig
{
get { return alreadComboContainingGrig; }
set { alreadComboContainingGrig= value; OnPropertyChanged("AlreadComboContainingGrig"); }
}
}
有可能吗?如果没有,那么你能告诉我任何替代方案吗?谢谢。
【问题讨论】:
标签: c# .net xaml silverlight mvvm