【问题标题】:Silverlight - specify stackpanel contents of a user control in the parentSilverlight - 在父级中指定用户控件的堆栈面板内容
【发布时间】:2010-09-23 03:47:14
【问题描述】:

我创建了一个名为“RibbonTabX”的用户控件,其中包含一个名为“spMain”的堆栈面板。我想做的是,当我在 xaml 中声明我的“RibbonTabX”实例时,在同一个 xaml 中,我想指定将在子 stackPanel 'spMain' 内的控件。这是使我想做的事情更加清晰的代码:

  <ribbon:RibbonTabX strHeaderText="Testing 123...">
          <ribbon:RibbonTabX.spMain>
              <sdk:Label Content="Hello" />
              <sdk:Label Content="World" />
          </ribbon:RibbonTabX.spMain>
   </ribbon:RibbonTabX>

在 RibbonTabX 的父级中,我想在我的用户控件“RibbonTabX”中指定堆栈面板的子内容。就像您可以使用“TabItem”控件一样。有什么想法可以做到这一点吗?

谢谢!

【问题讨论】:

    标签: silverlight user-controls layout


    【解决方案1】:

    您需要创建自定义内容控件,而不是用户控件。

    Start with this article

    它比用户控件更复杂,因为您必须为它手工制作通用模板,但它们更通用。

    【讨论】:

    • 完美!这正是我需要知道的。谢谢!
    【解决方案2】:

    您想使用 ContentControl。而不是指定这些控件进入堆栈面板,您可能应该只将内容放在堆栈面板中。让您的 RibbonTabX 派生自 ContentControl 而不是 UserControl,然后在适当的位置放置 &lt;ContentPresenter /&gt;,然后功能区的用户可以将任何内容放入其中。

    <ribbon:RibbonTabX strHeaderText="Testing 123..."> 
              <StackPanel> 
                  <sdk:Label Content="Hello" /> 
                  <sdk:Label Content="World" /> 
              </StackPanel> 
    </ribbon:RibbonTabX> 
    

    这是可能的最基本的 ContentControl:

    <ContentControl x:Class="SilverlightControl1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Grid x:Name="LayoutRoot" Background="Orange">
            <ContentPresenter />
        </Grid>
    </ContentControl>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-25
      • 1970-01-01
      • 2011-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多