I have a view model that inherits from ReactiveObject
from reactiveui.net, something like
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
}
I can get the following to display both design-time and run-time:
<Page.DataContext>
<local:TestViewModel />
</Page.DataContext>
<TextBlock Text="{Binding Nested.VMProperty}" />
<TextBlock Text="{Binding Nested.Suffix}" />
but when I try to do this instead, no text is displayed design-time:
<Page.DataContext><!-- ... -->
<TextBlock>
<Run Text="{Binding Nested.VMProperty}" />
<Run Text="{Binding Nested.Suffix}" />
</TextBlock>
Run-time it still works, but I don't want to have to deploy to the device emulator every time I want to check some pixel pushing...
How do I get these properties do display inside a <Run />
tag during design time?
IViewFor<T>
, but I can't have it inheritViewFor<T>
since also need to have my own base class, and I haven't been able to make it work with a generic base class. Also, because of how the VM layer is implemented (by someone else, i.e. out of my control), I must sometimes assign the viewmodel in theOnNavigatedTo
event handler. – Idealist