简体   繁体   English

如何在WPF中设置功能区窗口的用户控件?

[英]How to set the usercontrol for ribbon window in WPF?

First I've created a WPF application, then I added new RibbonWindows to the application, and called it RibbonWindow1. 首先,我创建了一个WPF应用程序,然后将新的RibbonWindows添加到该应用程序中,并将其命名为RibbonWindow1。 Now I want to set the content of the ribbon control via the code belowe and show the ribbon: 现在,我想通过下面的代码设置功能区控件的内容并显示功能区:

 RibbonWindow1 ribWindow = new RibbonWindow1
            {
                Title = "This is a ribbon window",
                Content = new UserControl1()
            };
            ribWindow.ShowDialog();

But I can't see the ribbon bar. 但是我看不到功能区栏。 If I remove content the ribbon will be shown, also if I use drag and drop I can show it, but I want to do it via simple code, dynamically. 如果删除内容,将显示功能区,如果使用拖放功能,也可以显示它,但是我想通过简单的代码动态地进行操作。 If I can dock the related control in a specific grid cell it will be helpful to me. 如果我可以将相关控件停靠在特定的网格单元中,则对我会有所帮助。 Any suggestions? 有什么建议么?

In my little experience with RibbonWindow, i saw that ribbon is part of the content of the ribbonwindow itself. 在我对RibbonWindow的一点经验中,我看到功能区是Ribbonwindow本身内容的一部分。 So, a solution could be to expose a public method for the ribbon window that set your usercontrol, like this: 因此,一种解决方案可能是公开用于设置用户控件的功能区窗口的公共方法,如下所示:

<ribbon:RibbonWindow ...>
<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <ribbon:Ribbon x:Name="Ribbon" />
    //add a container for your usercontrol
    <Grid Name="contentPlaceHolder" Grid.Row="1"></Grid>   
 </Grid>

and in the code you can set a method like 在代码中,您可以设置类似

public void SetControl(UserControl uc)
{
   this.contentPlaceHolder.Content = uc; 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM