将页面作为scrollviewer或contentControl等的内容
有没有办法将页面
放入< grid/>
,< stackpanel/>
,,
< contentControl/>
或< scrollviewer/>
用constructor调用从代码中作为内容?
我期望这样的事情:
xaml:
<Grid>
<ScrollViewer Content="{Binding Panel0}"/>
</Grid>
c#:
public class TestWindowViewModel : Page
{
public string Name { get; private set; }
public string Description { get; private set; }
public TestWindowViewModel(string name, string description)
{
Name = name;
Description = description;
}
}
_
public partial class SomeViewModel : Page
{
public TestWindowViewModel Panel0;
public SomeViewModel()
{
Panel0 = new TestWindowViewModel("panelName", "panelDescription");
InitializeComponent();
}
}
Is there a way to put a Page
inside a <Grid/>
, <StackPanel/>
, <ContentControl/>
or <ScrollViewer/>
as content from code using a constructor call?
I expect such things:
XAML:
<Grid>
<ScrollViewer Content="{Binding Panel0}"/>
</Grid>
C#:
public class TestWindowViewModel : Page
{
public string Name { get; private set; }
public string Description { get; private set; }
public TestWindowViewModel(string name, string description)
{
Name = name;
Description = description;
}
}
_
public partial class SomeViewModel : Page
{
public TestWindowViewModel Panel0;
public SomeViewModel()
{
Panel0 = new TestWindowViewModel("panelName", "panelDescription");
InitializeComponent();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
frame
标签,如果您不想在ViewModel中有一个道具,那么您应该能够
记住您的东西,即
testWindowViewModel
继承页面。这不是ViewModel。相反,这是一个普通的页面。您需要看起来像这样的东西:
并且您可以走更远的级别并进行抽象类:
然后您可以像这样继承ViewModel:
一旦正确地将其分开,您就可以使用框架并为SomePage和SomePageViewModel,然后您可以在ViewModel的帧内容上使用实际绑定。我知道这很长,但是如果您开始设置一个良好的MVVM设置,那么如果您进入异步,那么您就可以节省自己的头痛,而没有。
You can use a
Frame
tagIf you don't want to have a prop in your ViewModel then you should be able to do
Keep in mind you have something called
TestWindowViewModel
and it inherits Page. This is not a ViewModel. Instead it is a normal page.You want something that looks like this:
and you can go a level farther and make an abstract class:
and then you can just inherit ViewModel like so:
Once you get this all seperated out correctly you can use the frame and do the same for the SomePage and SomePageViewModel and then you can use actual binding on the Frame Content from the ViewModel. I know this is long winded, but if you start out right on setting up a good MVVM setup you will save yourself headache if you ever get into Async and what not.
在XAML中:
在CS:
内容为页面
in xaml:
in cs:
where content is Page