Silverlight Slider CustomConstrol properties not available
I've create a custom control with Blend 4 to customize a Slide object. Here a snipet of code generated by Blend:
<UserControl
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"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Silverlig开发者_JAVA技巧htControlCustomSlider.CustomSlider"
d:DesignWidth="640" d:DesignHeight="480">
<UserControl.Resources>
<Style x:Key="SliderStyle1" TargetType="Slider">
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Maximum" Value="10"/>
<Setter Property="Minimum" Value="0"/>
<Setter Property="Value" Value="0"/>
<Setter Property="BorderBrush">
Then I've build the project and imported it to VS2010. I can create an instance of the custom slider it has the same look and all. However, the properties Value, Maximum and Minimum (and maybe others) are not available. Like the custom control did not inherited from the slider. What am I doing wrong?
Thanks
Ok so there's a major difference in UserControls and Custom Controls. Although you didn't post all of your code, which i would suggest, it looks like what you have here is a UserControl that contains a Slider that has a customized StyleTemplate.
So basically, you're not creating a control that inheirits functionality from the Slider control, you're creating a control that CONTAINS a Slider. So that means you can't directly access the Slider properties, because the Usercontrol is not a type of Slider.
So, assuming you haven't actually changed any of the functionality of the Slider, and just the style, what you should do is reuse the Style template you have in your UserControl and apply it to a Slider Control as a resource.
精彩评论