开发者

How to set the usercontrol for ribbon window in WPF?

开发者 https://www.devze.com 2023-01-20 12: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

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 开发者_StackOverflow中文版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. 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; 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消