How to set the usercontrol for ribbon window in WPF?

北城余情 提交于 2019-12-24 02:43:14

问题


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?


回答1:


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>

and in the code you can set a method like

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


来源:https://stackoverflow.com/questions/3921934/how-to-set-the-usercontrol-for-ribbon-window-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!