如何设置在WPF区窗口的用户控件? [英] How to set the usercontrol for ribbon window in WPF?

查看:143
本文介绍了如何设置在WPF区窗口的用户控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我创建了一个WPF应用程序,然后我增加了新的RibbonWindows到应用程序,并把它称为RibbonWindow1。现在,我想设置通过代码belowe色带控制的内容和显示的功能区:

First I've created a WPF application, then I added new RibbonWindows to the application, and called it 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?

推荐答案

在我与RibbonWindow一点经验,我看到丝带是ribbonwindow本身的内容的一部分。所以,解决办法是公开为设置你的用户控件,这样的功能区窗口的公共方法:

In my little experience with RibbonWindow, i saw that ribbon is part of the content of the ribbonwindow itself. 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>



和代码,你可以设置像

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

这篇关于如何设置在WPF区窗口的用户控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆