Silverlight 3 n'affiche pas le modèle par défaut pour un contrôle personnalisé sur lequel je travaille.Silverlight 3 n'affiche pas le modèle par défaut d'un contrôle personnalisé
J'ai trois projets dans ma solution:
- CustomControl.Controls - Silverlight Bibliothèque de classes
- CustomControl.Silverlight - application Silverlight
- CustomControl.Silverlight.Web - Web Application
Dans CustomControl.Controls J'ai la classe suivante:
[TemplateVisualState(Name = "Normal", GroupName = "FocusStates")]
public class SampleControl : ContentControl
{
public SampleControl()
{
DefaultStyleKey = typeof(SampleControl);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
UpdateVisualState(false);
}
void UpdateVisualState(bool useTransitions)
{
VisualStateManager.GoToState(this, "Normal", useTransitions);
}
}
Thèmes/generic.xaml est configuré en tant que ressource Embeded et contient les éléments suivants:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="controls:SampleControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:SampleControl">
<Border Background="Orange" CornerRadius="5" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Enfin, je suis en utilisant le contrôle personnalisé à l'intérieur MainPage XAML dans CustomControl.Silverlight:
<UserControl x:Class="CustomControl.Silverlight.MainPage"
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"
xmlns:sample="clr-namespace:CustomControl.Controls;assembly=CustomControl.Controls"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<StackPanel x:Name="LayoutRoot">
<sample:SampleControl Width="100" Height="200" />
<Button Width="100" Height="200" Content="bar" />
</StackPanel>
</UserControl>
dans le navigateur, le SampleControl n'est pas visible (il occupe toujours 200px en hauteur, il est là) et en dessous, ab utton est affiché. J'utilise Visual Studio 2008 SP1 + Silverlight 3 Tools. Je suis en train d'utiliser les outils Visual Studio 2008 SP1 + Silverlight 3.
Y at-il autre chose que je dois faire pour que le modèle défini dans Thèmes/generic.xaml soit appliqué à SampleControl?
Merci