Sta*_*ajs 6 wpf user-controls design-time-data caliburn.micro visual-studio-2013
使用VS2013和Caliburn.Micro 2.0.2
鉴于此示例:
Name属性:
似乎在设计时,嵌套视图模型属性被忽略.有没有办法支持这个?
public class NestedViewModel : PropertyChangedBase
{
private string _name;
public string Name
{
get { return _name; }
set
{
_name = value;
NotifyOfPropertyChange(() => Name);
}
}
public NestedViewModel()
{
Name = "Nested";
}
}
Run Code Online (Sandbox Code Playgroud)
<UserControl
x:Class="WpfApplication1.Views.NestedView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cal="http://www.caliburnproject.org"
xmlns:viewModels="clr-namespace:WpfApplication1.ViewModels"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=viewModels:NestedViewModel, IsDesignTimeCreatable=True}"
cal:Bind.AtDesignTime="True">
<Grid>
<Label x:Name="Name" FontSize="16" Background="LightGreen"/>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
绿色标签显示Name设计器中嵌套视图模型的正确性:

public class ShellViewModel : PropertyChangedBase
{
private string _name;
private NestedViewModel _nestedViewModel;
public string Name
{
get { return _name; }
set
{
_name = value;
NotifyOfPropertyChange(() => Name);
}
}
public NestedViewModel NestedViewModel
{
get { return _nestedViewModel; }
set
{
if (Equals(value, _nestedViewModel)) return;
_nestedViewModel = value;
NotifyOfPropertyChange(() => NestedViewModel);
}
}
public ShellViewModel()
{
NestedViewModel = new NestedViewModel();
Name = "Shell";
}
}
Run Code Online (Sandbox Code Playgroud)
<UserControl
x:Class="WpfApplication1.Views.ShellView"
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:viewModels="clr-namespace:WpfApplication1.ViewModels"
xmlns:cal="http://www.caliburnproject.org"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=viewModels:ShellViewModel, IsDesignTimeCreatable=True}"
cal:Bind.AtDesignTime="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<ContentControl Grid.Row="0" x:Name="NestedViewModel"/>
<Label Grid.Row="1" x:Name="Name" FontSize="16" Background="RoyalBlue"/>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
绿色标签应显示设计器中的嵌套视图模型Name属性,而是显示shell视图模型的值:

它在运行时正确绑定:

| 归档时间: |
|
| 查看次数: |
570 次 |
| 最近记录: |