WPF 动态添加 RibbonApplicationMenuItem(s)
我有以下代码:
<ribbon:Ribbon.ApplicationMenu>
<ribbon:RibbonApplicationMenu ToolTipTitle="Application Menu">
<ribbon:RibbonApplicationMenuItem Header="Company"
x:Name="MenuItem_Company"
ImageSource="Images\LargeIcon.png"
Command="{Binding Path=CompanyCommand}">
<StackPanel>
<TextBlock Text="Item 1 in the list" />
<TextBlock Text="Item 2 in the list" />
<TextBlock Text="Item 3 in the list" />
<TextBlock Text="Item 4 in the list" />
</StackPanel>
</ribbon:RibbonApplicationMenuItem>
<ribbon:RibbonApplicationMenuItem Header="DocStore Settings"
x:Name="MenuItem1"
ImageSource="Images\LargeIcon.png"
Click="MenuItem1_Click"/>
<ribbon:RibbonApplicationMenuItem Header="About DocStore"
x:Name="MenuItem2"
ImageSource="Images\LargeIcon.png"
Click="MenuItem2_Click" />
<ribbon:RibbonApplicationMenuItem Header="Exit"
x:Name="MenuExit"
ImageSource="Images\LargeIcon.png"
Click="Exit" />
</ribbon:RibbonApplicationMenu>
</ribbon:Ribbon.ApplicationMenu>
我想将项目动态添加到第一个 RibbonApplicationMenuItem 内的堆栈面板,替换硬编码的 TextBlock 项目。我不知道有多少个,我以4个为例。
这可能吗?如果是这样,我该如何去做呢?
谢谢! 埃罗克
I have the following code:
<ribbon:Ribbon.ApplicationMenu>
<ribbon:RibbonApplicationMenu ToolTipTitle="Application Menu">
<ribbon:RibbonApplicationMenuItem Header="Company"
x:Name="MenuItem_Company"
ImageSource="Images\LargeIcon.png"
Command="{Binding Path=CompanyCommand}">
<StackPanel>
<TextBlock Text="Item 1 in the list" />
<TextBlock Text="Item 2 in the list" />
<TextBlock Text="Item 3 in the list" />
<TextBlock Text="Item 4 in the list" />
</StackPanel>
</ribbon:RibbonApplicationMenuItem>
<ribbon:RibbonApplicationMenuItem Header="DocStore Settings"
x:Name="MenuItem1"
ImageSource="Images\LargeIcon.png"
Click="MenuItem1_Click"/>
<ribbon:RibbonApplicationMenuItem Header="About DocStore"
x:Name="MenuItem2"
ImageSource="Images\LargeIcon.png"
Click="MenuItem2_Click" />
<ribbon:RibbonApplicationMenuItem Header="Exit"
x:Name="MenuExit"
ImageSource="Images\LargeIcon.png"
Click="Exit" />
</ribbon:RibbonApplicationMenu>
</ribbon:Ribbon.ApplicationMenu>
I'd like to dynamically add items to my stack panel inside the first RibbonApplicationMenuItem replacing the TextBlock items that are hardcoded. I don't know how many will be available, I put 4 as an example.
Is this possible? If so, how do I go about doing it?
Thanks!
Eroc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是我在 XAML 中所做的,我删除了堆栈面板:
以及表单背后的代码:
我希望这对每个人都有帮助,它似乎对我有用!
This is what I did in the XAML, I dropped the stack panel:
And the code behind the form:
I hope this helps everyone, it seemed to work for me!