Click here to Skip to main content
15,919,422 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Creating Custom Button control using Asp.Net Pin
Michael Sync2-Jun-08 18:15
Michael Sync2-Jun-08 18:15 
QuestionRe: Creating Custom Button control using Asp.Net Pin
VijaySofist3-Jun-08 18:45
VijaySofist3-Jun-08 18:45 
AnswerRe: Creating Custom Button control using Asp.Net Pin
Michael Sync4-Jun-08 20:16
Michael Sync4-Jun-08 20:16 
QuestionRe: Creating Custom Button control using Asp.Net Pin
VijaySofist4-Jun-08 23:59
VijaySofist4-Jun-08 23:59 
AnswerRe: Creating Custom Button control using Asp.Net Pin
Michael Sync5-Jun-08 2:20
Michael Sync5-Jun-08 2:20 
AnswerScaling woes Pin
Ray Hayes1-Jun-08 6:01
Ray Hayes1-Jun-08 6:01 
GeneralRe: Scaling woes Pin
TJoe3-Jun-08 2:22
TJoe3-Jun-08 2:22 
GeneralRe: Scaling woes Pin
Ray Hayes3-Jun-08 11:40
Ray Hayes3-Jun-08 11:40 
Tom,

thanks for your reply. Your suggestions make a lot of sense and have, I feel, pointed me in the right direction. Although I think I'm messing up on step 6!

This is what I've done so far:
TJoe wrote:
1. Create a separate class (e.g. ScaleFactor) with a single property (e.g. Value)
2. Implement INotifyPropertyChanged in the ScaleFactor class and fire it when the Value changes.

public class VisualScale : INotifyPropertyChanged
{
    private double scale = 1.0;
    public double ScalingFactor
    {
        get { return scale; }
        set { scale = value; NotifyPropertyChanged("Scale changed"); }
    }

    #region INotifyPropertyChanged Members
    private void NotifyPropertyChanged(String info)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;
    #endregion
}
TJoe wrote:
3. Create an IMultiValueConverter that takes two values: 1st will be the "value" from your underlying data (you don't have to use a TypeConverter, but you probably can), 2nd will be the scale factor. The IMultiValueConverter will then multiply the two values and return that.

public class WidthScaler : IMultiValueConverter
{
    #region IMultiValueConverter Members
    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if ( targetType != typeof(double) )
        {
            throw new NotSupportedException("Target type of WidthScaler must be double");
        }

        if ( values.Length != 2 || 
             values[0].GetType() != typeof(double) || 
             values[1].GetType() != typeof(double) )
        {
            throw new NotSupportedException("Source values should be a pair of doubles");
        }

        return (double) values[0]*(double) values[1];
    }

    public object[] ConvertBack(object value,
                                Type[] targetTypes,
                                object parameter,
                                System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
    #endregion
}
TJoe wrote:
4. Define an instance of ScaleFactor in the Window's resource section.
5. Define an instance of your converter from #3 in the Window's resource section.

    <Window.Resources>
        <local:Database x:Key="data" x:Name="data"/>
        <local:VisualScale x:Key="scale" x:Name="scale" />
        <local:WidthScaler x:Key="widthScaler" x:Name="widthScaler" />
TJoe wrote:
6. Update the Border's width to be a MultiBinding using your converter with the "value" and scale factor (from #4) as your input values.

        <DataTemplate x:Key="programmeTemplate">
            <Border>
                <Border.Width>
                    <MultiBinding Converter="{StaticResource widthScaler}"
                                  ConverterParameter="">
                        <Binding Path="{Binding Duration}" />
                        <Binding Path="widthScaler"/>
                    </MultiBinding>
                </Border.Width>

I think I've either made the mistake in the bit above, or this bit...
<Slider x:Name="scaleSlider" Width="100" Minimum="0.5" Maximum="10.0" Value="{Binding Path=widthScaler}"/>

This is the exception I get is "A 'Binding' cannot be set on the 'Path' property of type 'Binding'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.". Whilst your reply has helped a lot, I've obviously not got the WPF gene kick in yet! Wink | ;-)

Regards,
Ray

GeneralRe: Scaling woes Pin
Ray Hayes3-Jun-08 11:53
Ray Hayes3-Jun-08 11:53 
GeneralRe: Scaling woes Pin
TJoe4-Jun-08 1:56
TJoe4-Jun-08 1:56 
GeneralRe: Scaling woes Pin
Ray Hayes4-Jun-08 2:10
Ray Hayes4-Jun-08 2:10 
GeneralRe: Scaling woes Pin
TJoe4-Jun-08 2:13
TJoe4-Jun-08 2:13 
GeneralRe: Scaling woes Pin
Ray Hayes4-Jun-08 2:22
Ray Hayes4-Jun-08 2:22 
GeneralRe: Scaling woes Pin
TJoe4-Jun-08 2:25
TJoe4-Jun-08 2:25 
GeneralRe: Scaling woes Pin
Ray Hayes4-Jun-08 2:32
Ray Hayes4-Jun-08 2:32 
GeneralRe: Scaling woes Pin
TJoe4-Jun-08 2:37
TJoe4-Jun-08 2:37 
GeneralRe: Scaling woes Pin
Ray Hayes4-Jun-08 2:45
Ray Hayes4-Jun-08 2:45 
GeneralRe: Scaling woes Pin
TJoe4-Jun-08 2:47
TJoe4-Jun-08 2:47 
GeneralRe: Scaling woes Pin
TJoe4-Jun-08 2:50
TJoe4-Jun-08 2:50 
GeneralRe: Scaling woes Pin
Ray Hayes4-Jun-08 2:52
Ray Hayes4-Jun-08 2:52 
GeneralRe: Scaling woes Pin
Member 36739221-Jul-09 19:56
Member 36739221-Jul-09 19:56 
Questionerror while opening new window from a Asynchronou callback function Pin
vayanan31-May-08 11:15
vayanan31-May-08 11:15 
AnswerRe: error while opening new window from a Asynchronou callback function Pin
User 2710091-Jun-08 11:25
User 2710091-Jun-08 11:25 
QuestionRouted Command passing data Pin
Jammer31-May-08 7:39
Jammer31-May-08 7:39 
AnswerRe: Routed Command passing data Pin
User 2710091-Jun-08 11:27
User 2710091-Jun-08 11:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.