This project is read-only.

Custom Control resizing?

Nov 7, 2012 at 5:45 PM

I have to use a Slider in the Ribbon. So I used the Slider of the WPF Libary and created a template for it. That Slider is contained by a UserControl that also contains a few other controls. Now I have to handle resizing of the whole usercontrol. How can I implement something like that I can use SizeDefinition Middle, Small, Small. I tried to implement the IRibbonControl interface and the IScalableRibbonControl interface. But the implemented properties and methods aren't called. So how can i implement my own controls?

Nov 8, 2012 at 11:15 AM

Can you send me a small repro of your code?

Nov 9, 2012 at 9:04 AM

I just have a little xaml code until now:

<UserControl x:Class="HTLED.WPF.Templates.AudioSeekPanel"
             d:DataContext="{d:DesignInstance ViewModel:MainAudioPlayerViewModel}"
             d:DesignHeight="100" d:DesignWidth="300">
        <Slider Minimum="0" Maximum="1" Value="{Binding SeekPanelViewModel.Position}" LargeChange="0.0001" TickFrequency="0.0001"
                VerticalAlignment="Bottom" Margin="0,5"/>
        <DockPanel Grid.Row="1" LastChildFill="False" VerticalAlignment="Top">
            <TextBlock Text="{Binding SeekPanelViewModel.RawPosition, StringFormat=hh\\:mm\\:ss, FallbackValue=00:00}" DockPanel.Dock="Left"/>
            <TextBlock Text="{Binding SeekPanelViewModel.RawLength, StringFormat=hh\\:mm\\:ss, FallbackValue=00:00}" DockPanel.Dock="Right"/>

Now I would like to handle resizing in the codebehind.

Nov 9, 2012 at 8:51 PM
Edited Nov 9, 2012 at 8:55 PM

I never tried this myself, but according to the code you have to do the following:

- implement IRibbonControl on your control

- implement the Size-Property this way:

#region Size Property

/// <summary>
/// Using a DependencyProperty as the backing store for Size.  
/// This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty SizeProperty = RibbonControl.SizeProperty.AddOwner(typeof(YOURCONTROLTYPE));
/// <summary>
/// Gets or sets Size for the element
/// </summary>
public RibbonControlSize Size
    get { return (RibbonControlSize)GetValue(SizeProperty); }
    set { SetValue(SizeProperty, value); }


- implement the SizeDefiniton-Property this way:

 #region SizeDefinition Property

/// <summary>
/// Using a DependencyProperty as the backing store for SizeDefinition.  
/// This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty SizeDefinitionProperty = RibbonControl.AttachSizeDefinition(typeof(YOURCONTROLTYPE));            
/// <summary>
/// Gets or sets SizeDefinition for element
/// </summary>
public string SizeDefinition
    get { return (string)GetValue(SizeDefinitionProperty); }
    set { SetValue(SizeDefinitionProperty, value); }


 This should make it possible to react to changes to the Size-Property.
At least this is the way it's done in Ribbon-Controls like Button.

Nov 9, 2012 at 8:56 PM

I forgot to mention that you need the source version starting with as RibbonControl.AttachSizeDefinition was internal before that version.

Nov 11, 2012 at 10:06 AM

Ok thank you so much. Such a nice support on codeplex is quite rarely