I’m now creating one custom silverlight button. As I want to get the visual states, I don’t want to use style or control template. So, I’ve written like this:
<Button x:Class="MyNameSpace.MyImageButton"
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">
<Grid x:name="LayoutRoot">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup ...
</VisualStateGroup>
<VisualStateManager.VisualStateGroups>
<Border (Various border styles)
<StackPanel x:Name="ContentPresenter" Orientation="Horizontal">
<Image Source="{Binding Path=this.ImageSource}" Stretch="Fill" />
<!--ContentPresenter-->
<ContentPresenter HorizontalAlignment="{Binding Path=this.HorizontalContentAlignment}"
VerticalAlignment="{Binding Path=this.VerticalContentAlignment}" >
<TextBlock Text="{Binding Path=this.Content}" />
</ContentPresenter>
</StackPanel>
</Border>
</Grid>
<Button.BorderBrush>
.....
<Button.BorderBrush>
</Button>
But the styling doesn’t seem to work. It shows the default button style. How to make it work. I’ve also registered an Image source property. That also does not seem to work.
Please help. Thanks in advance.
Actually in Silverlight 4 you can’t go without style if you are using a button. I tried a lot. Even I tried to give some colour to the borders I declared in the Button. Lastly I used made a separate control deriving from
UserControl. It helped me a lot. Surely it don’t give me the flexibility of a button but it gave me what I wanted. I can now select the Visual states from the control directly.