Xaml `<;运行/>;`不';设计时间内的t数据绑定

Xaml `<;运行/>;`不';设计时间内的t数据绑定,xaml,windows-phone-8.1,reactiveui,Xaml,Windows Phone 8.1,Reactiveui,我有一个从ReactiveObjectfrom继承的视图模型,类似 public sealed class TestViewModel : ReactiveObject { public sealed class NestedViewModel { private string _property; public string VMProperty { get { return _property; }

我有一个从
ReactiveObject
from继承的视图模型,类似

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>

运行时它仍然可以工作,但我不想每次检查像素推送时都必须部署到设备模拟器


如何使这些属性在设计时显示在
标记中?

在绑定中使用
回退值如何?我经常使用它来检查绑定内容的外观,并且没有任何问题

ReactiveUI框架的创建者Paul Betts主张将示例数据硬编码到页面的XAML中:

<TextBlock>
 <Run Text="Test String" x:Name="VMproperty" />
 <Run Text="with suffix" x:Name="Suffix" />
</TextBlock>
这些反应式UI样式绑定覆盖XAML中硬编码的示例数据。因此,您可以在设计时获得示例数据,并在运行时获得数据绑定


来源:

这可能不是你所希望的,但是WP7@AndersGustafsson已经讨论并回答了一个类似的案例。谢谢你的提示,虽然它并不能解决我的问题。我已经对DesighData做了一些处理,而且似乎使用Run方法的TextBlock不会像你提到的那样工作。另一件事是,当在DataTemplate中使用此组合(TB与Run)时,它将在设计模式下成功工作-您可以查看-请参阅MainPage.xaml。您在哪里进行视图与viewmodel之间的链接。该视图假定使用ViewFor。。。如果这样做,那么xaml的使用就过时了。你的想法?@DeJaVo:我确实让页面实现了
IViewFor
,但我不能让它继承
ViewFor
,因为我还需要有自己的基类,而且我还不能让它与通用基类一起工作。此外,由于VM层是如何实现的(由其他人实现的,即我无法控制),我有时必须将
onnavigated中的viewmodel分配给
事件处理程序。这是一个好主意,但是
FallbackValue
也不会在设计时呈现任何内容…:(进行了更多的搜索,但不幸的是在设计时无法工作。我只需在VM上创建另一个属性,将VMProperty和后缀组合为单个字符串。。不幸的是,在这个项目中,我没有VM层的能力-它们使用Xamarin在多个平台上共享。但因为似乎没有任何其他选项我看看能不能把这个修好。
this.OneWayBind(ViewModel, vm => vm.VMproperty, v => v.VMproperty.Text);
this.OneWayBind(ViewModel, vm => vm.Suffix, v => v.Suffix.Text);