Custom Control resizing?

Nov 7, 2012 at 4: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?

Developer
Nov 8, 2012 at 10:15 AM

Can you send me a small repro of your code?

Nov 9, 2012 at 8:04 AM

I just have a little xaml code until now:

<UserControl x:Class="HTLED.WPF.Templates.AudioSeekPanel"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ViewModel="clr-namespace:HTLED.Client.ViewModel;assembly=HTLED.Client"
             mc:Ignorable="d" 
             d:DataContext="{d:DesignInstance ViewModel:MainAudioPlayerViewModel}"
             d:DesignHeight="100" d:DesignWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <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"/>
        </DockPanel>
    </Grid>
</UserControl>

Now I would like to handle resizing in the codebehind.

Developer
Nov 9, 2012 at 7:51 PM
Edited Nov 9, 2012 at 7: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); }
}

#endregion

- 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); }
}

#endregion

 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.

 
Developer
Nov 9, 2012 at 7:56 PM

I forgot to mention that you need the source version starting with http://fluent.codeplex.com/SourceControl/changeset/e381b08e7687 as RibbonControl.AttachSizeDefinition was internal before that version.

Nov 11, 2012 at 9:06 AM

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