【发布时间】:2015-05-18 10:38:50
【问题描述】:
我有一个从ReactiveObject 继承自reactiveui.net 的视图模型,类似于
public sealed class TestViewModel : ReactiveObject
{
public sealed class NestedViewModel
{
private string _property;
public string VMProperty
{
get { return _property; }
set { this.RaiseAndSetIfChanged(ref _property, value); }
}
private string _suffix;
public string Suffic
{
get { return _suffix; }
set { this.RaiseAndSetIfChanged(ref _suffix, value); }
}
}
private NestedViewModel _nested = new NestedViewModel();
public Nested
{
get { return _nested; }¨
set { this.RaiseAndSetIfChanged(ref _nested, value); }
}
#if DEBUG
public TestViewModel() {
Nested.VMProperty = "Test string";
Nested.Suffix = "with suffix";
}
#endif
}
我可以得到以下内容来显示设计时和运行时:
<Page.DataContext>
<local:TestViewModel />
</Page.DataContext>
<TextBlock Text="{Binding Nested.VMProperty}" />
<TextBlock Text="{Binding Nested.Suffix}" />
但是当我尝试这样做时,设计时没有显示任何文本:
<Page.DataContext><!-- ... -->
<TextBlock>
<Run Text="{Binding Nested.VMProperty}" />
<Run Text="{Binding Nested.Suffix}" />
</TextBlock>
运行时它仍然可以工作,但我不想每次我想检查一些像素推送时都必须部署到设备模拟器......
如何让这些属性在设计时显示在 <Run /> 标记内?
【问题讨论】:
-
这可能不是您所希望的,但是类似的案例已经为 WP7 here987654322@ 进行了讨论和回答
-
@AndersGustafsson 感谢您的提示,尽管它并不能解决我的问题。
-
我用 DesighData 玩了一点,似乎 TextBlock 和 Run 方法不起作用就像你在问题中提到的那样。另一件事是,当在 DataTemplate 中使用时,这种组合(TB 与 Run)将成功地在设计模式下工作 - 您可以查看 my sample - 请参阅 MainPage.xaml。
-
你在哪里做view和viewmodel的联动。该视图假设使用 ViewFor
... 如果您这样做,则 xaml 的使用已过时。你的想法? -
@DeJaVo:我确实让页面实现了
IViewFor<T>,但我不能让它继承ViewFor<T>,因为我还需要有自己的基类,而我一直无法使其与通用基类一起使用。此外,由于 VM 层的实现方式(由其他人实现,即不受我控制),有时我必须在OnNavigatedTo事件处理程序中分配视图模型。
标签: xaml windows-phone-8.1 reactiveui