【问题标题】:Show contents of Window in ContentControl在 ContentControl 中显示 Window 的内容
【发布时间】:2013-03-19 13:57:46
【问题描述】:

我有一个名为InstallerView 的窗口,并希望通过ContentControl 在另一个窗口中显示其内容。目前这不起作用的正确语法是什么?

<ContentControl Content="{StaticResource ResourceKey=InstallerView}" Grid.Column="0" Grid.Row="1" Height="430" />

窗口是这样定义的

<Window x:Class="MyBootstrapper.InstallerView" .... >

【问题讨论】:

  • 您的意思是希望ContentControl 在运行时在单独的InstallerView 中显示正在发生的事情的实时视图?或者您想在ContentControl 中嵌入InstallerView,就好像它是一个用户控件一样?
  • 像用户控件一样嵌入它:)
  • 是否有理由不能将内容改为UserControl?然后在你的两个窗口中使用UserControl
  • 我正在使用 WiX 编写一个安装程序,因此它目前是一个嵌入在控件库中的窗口,测试它有点困难,因为我必须构建安装程序并在调试器之外运行它,所以我希望通过将其嵌入到另一个应用程序中,以一种快速且便宜的方式对其进行测试

标签: c# .net wpf silverlight contentcontrol


【解决方案1】:

InstallerView 不是您的窗口的名称,而是您的班级的名称。因此,您可以执行以下操作,尽管我不建议这样做。

<Grid> <!-- I need a layout control -->
    <Grid.Resources>
        <someNs:InstallerView x:Key="IView" /> 
        <!-- someNs = the namespace of your InstallerView class -->
    </Grid.Resources>
    <!-- Now you can use the resource -->
    <ContentControl Content="{StaticResource IView}" />
</Grid>

【讨论】:

    猜你喜欢
    • 2012-09-24
    • 1970-01-01
    • 1970-01-01
    • 2010-11-16
    • 1970-01-01
    • 2021-12-15
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多