Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8042915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:44:36+00:00 2026-06-05T04:44:36+00:00

I have a custom usercontrol with that code: public partial class AudioControl : UserControl

  • 0

I have a custom usercontrol with that code:

public partial class AudioControl : UserControl
{
    public AudioControl()
    {
        InitializeComponent();
        Value = 0.1;
        DataContext = this;
    }

    public event RoutedPropertyChangedEventHandler<double> ValueChanged = delegate { };

    public int TextWidth
    {
        get { return (int)GetValue(TextWidthProperty); }
        set { SetValue(TextWidthProperty, value); }
    }

    public int SliderWidth
    {
        get { return (int)GetValue(SliderWidthProperty); }
        set { SetValue(SliderWidthProperty, value); }
    }

    public string Header
    {
        get { return (string)GetValue(TextBlock.TextProperty); }
        set { SetValue(TextBlock.TextProperty, value); }
    }

    //public double Value
    //{
    //    get { return (double)GetValue(Slider.ValueProperty); }
    //    set { SetValue(Slider.ValueProperty, value); }
    //}

    public double Value
    {
        get {
            return (double)GetValue(ValueProperty); 
        }
        set { 
            SetValue(ValueProperty, value);
        }
    }

    public static readonly DependencyProperty ValueProperty =
        DependencyProperty.Register("Value", typeof(double), typeof(AudioControl), new UIPropertyMetadata(0));

    public static readonly DependencyProperty TextWidthProperty =
        DependencyProperty.Register("TextWidth", typeof(int), typeof(AudioControl), new UIPropertyMetadata(0));

    public static readonly DependencyProperty SliderWidthProperty =
        DependencyProperty.Register("SliderWidth", typeof(int), typeof(AudioControl), new UIPropertyMetadata(0));

    private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
    {
        ValueChanged(this, e);
    }
}

And this XAML:

<UserControl x:Class="Controller.Audio.AudioControl"
         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:Audio="clr-namespace:Controller.Audio"
         mc:Ignorable="d" 
         d:DesignHeight="23" d:DesignWidth="500" x:Name="audioControl">
<UserControl.Resources>
    <Audio:DoubleToIntConverter x:Key="doubleToInt"/>
</UserControl.Resources>
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="{Binding TextWidth}"/>
        <ColumnDefinition Width="40"/>
        <ColumnDefinition Width="{Binding SliderWidth}"/>
    </Grid.ColumnDefinitions>

    <Label x:Name="txtBlock" Margin="0,0,10,0">
        <Binding Path="Header"/>
    </Label>
    <Label Grid.Column="1" Content="{Binding ElementName=slider, Path=Value, Converter={StaticResource doubleToInt}}"/>
    <Slider x:Name="slider" Grid.Column="2" Style="{StaticResource Office2010SilverSliderStyle}" 
            Value="{Binding Path=Value, ElementName=audioControl}" Minimum="0.0" Maximum="1.0" LargeChange="0.25" TickFrequency="0.01" ValueChanged="Slider_ValueChanged"/>
</Grid>

So if i start it I get an exception that something with the value binding is wrong. I also tried the commented version (the value-Property). There is no exception but if i set the value of that property my slider does not change.

Does anyone has any idea why? I ve never done something like that 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:44:38+00:00Added an answer on June 5, 2026 at 4:44 am

    There’s an error in the following dependency property declaration:

    public static readonly DependencyProperty ValueProperty =
        DependencyProperty.Register("Value", typeof(double), typeof(AudioControl), new UIPropertyMetadata(0));
    

    The problem here is that you’re defining the dependency property to be of type double, but giving it a default value 0 that is an int. Try changing 0 to 0.0.

    I ran your code and encountered an exception. The innermost exception contained the following message:

    Default value type does not match type of property ‘Value’.

    I changed the 0 in the line above to 0.0 and the problem went away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, please look at this custom Button-inherited UserControl code: Public Class UserControl1 Dim _Text
I have a Custom usercontrol that I want to enlarge. I tested this whit
Before I start, I have this code inside of a Custom Usercontrol: private DependencyProperty
I have a custom UserControl that contains a grid ...I wish to set the
I have a custom control that inherits from UserControl , and I can't get
I have a custom base user control in silverlight. <UserControl x:Class=Problemo.MyBaseControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008
I have a custom WPF control which consist of single TextBox <UserControl HorizontalAlignment=Left x:Class=WPFDiagramDesignerControl.Components.UcWBSBlock
I have a custom UserControl that consists of a ListBox with a DataTemplate .
I have a custom usercontrol that does a little animation on a DispatcherTimer tick,
i have a customer control that inherit from the UserControl class and i have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.