Custom Styles with Bindings

Jun 3, 2013 at 8:35 PM
Hi ¡¡,

I am trying to integrate the Fluent Ribbon in my project, my idea is to have in a static class the ribbon data and bind to it. By this way, I can control all the properties of each control in the Ribbon from whatever usercontrol or window.

For doing easier this task, I need to create custom styles like this :
<!-- RibbonButton -->
<Style x:Key="RibbonButtontyle" TargetType="{x:Type Rbb:Button}">
<Setter Property="Command" Value="{Binding Command}" />
  <Setter Property="Header" Value="{Binding Header}" />
  <Setter Property="LargeIcon" Value="{Binding LargeIcon, Converter={StaticResource UriToBitmapImageConverter}}" />
  <Setter Property="Visibility" Value="{Binding IsVisible, Converter={StaticResource BooleanToVisibilityConverter}}" />
  <Setter Property="IsEnabled" Value="{Binding IsEnabled}" />
</Style>
Once done this, the Ribbon Xaml would be :
<Rbb:RibbonGroupBox x:Name="Actions" 
  DataContext="{x:Static Infr:LyceRibbonModel.ActionsGroup}">
  <Rbb:Button DataContext="{x:Static Infr:MyRibbonModel.AcceptButton}" />
  <Rbb:Button DataContext="{x:Static Infr:MyRibbonModel.CancelButton}" />
</Rbb:RibbonGroupBox>
MyRibbonModel is a static class which contains the data which i want bind.

This way of binding not works, and the only way that works for me is this :
<Rbb:Button DataContext="{x:Static Infr:LyceRibbonModel.CopyButton}" 
                   Header="{Binding Header}" 
                   LargeIcon="{Binding Icon, Converter={StaticResource UriToBitmapImageConverter}}"
                   Command="{Binding Command}"
                   Visibility="{Binding IsVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
                   IsEnabled="{Binding IsEnabled}" />
I need to know if exists any way to create custom styles for Ribbon controls like the showed in the previous code to reduce the amount of XAML in the Ribbon declaration.

Thanks.