SplitButton template

Ribbon for WPF Forum

Posted 16 years ago by ddang
Version: 3.5.0429
Avatar
Hi
I have 2 SplitButtons with XAML code like this:

<StackPanel Orientation="Horizontal" Grid.Row="1">
<ribbon:SplitButton Margin="10" Label="Phone Number 1">
<ribbon:Menu>
<ribbon:Button Label="Menu Item #1" />
<ribbon:Button Label="Menu Item #1" />
<ribbon:Button Label="Menu Item #1" />
<ribbon:Button Label="Menu Item #1" />
<ribbon:Button Label="Menu Item #1" />
</ribbon:Menu>
</ribbon:SplitButton>
<ribbon:SplitButton Margin="10" Label="Phone Number 2">
<ribbon:Menu ItemsSource="{Binding Items}">
<ribbon:Menu.ItemTemplate>
<DataTemplate>
<ribbon:Button Label="{Binding}" MinWidth="100" />
</DataTemplate>
</ribbon:Menu.ItemTemplate>
</ribbon:Menu>
</ribbon:SplitButton>
</StackPanel>

Nothing difference except for one use in-line MenuItem and one use ItemsSource binding.
and here is the result
http://lh3.ggpht.com/datdtan/SQX91ZPEWmI/AAAAAAAAC6E/28wBjPu2S5w/s800/splitbutton.PNG

Do you know the reason why background of two menus is difference?
Thanks,
Danny

Comments (2)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Danny,

Based on your two examples, you would need to set the Context property on the Button, in your ItemTemplate. So something like this would work:
<ribbon:Menu.ItemTemplate> 
   <DataTemplate> 
      <ribbon:Button Label="{Binding}" MinWidth="100" Context="MenuItem" /> 
   </DataTemplate> 
</ribbon:Menu.ItemTemplate>
The two Menus ultimately differ in what is contained in the "Items" collection. In the first case the Items would contain a list of Buttons, in the second case the Items(presumably) contain a list of strings. In the former case, the Menu can correctly set the Context on the Button automatically. In the latter case, we cannot set the Context on the string, so you would need to do it manually in your ItemTemplate.


Actipro Software Support

Posted 16 years ago by ddang
Avatar
It works perfectly.
Thank you very much.
Danny
The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.