Все привет!) Кто нибудь, подскажите плиз!! уже замучался бороться, хочется сделать как надо, но не получается.. Пытаюсь создать свой пользовательский элемент управления, который должен иметь несколько визуальных состояний. Но никак не получается это сделать, вот что я делаю:
| Код | <ContentControl x:Class="TestVSM.UserControl1" xmlns:thisApp="clr-namespace:TestVSM" 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" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Style="{DynamicResource UserControlStyle}"> <ContentControl.Resources> <Style x:Key="UserControlStyle" TargetType="ContentControl"> <Setter Property="Background" Value="Lavender"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ContentControl"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="MyGroup"> <VisualState x:Name="State1"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="UserControlContent" Storyboard.TargetProperty="(Content).Children[0].(UIElement.Visibility)"> <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="UserControlContent" Storyboard.TargetProperty="(Content).Children[1].(UIElement.Visibility)"> <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="State2"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="UserControlContent" Storyboard.TargetProperty="(Content).Children[1].(UIElement.Visibility)"> <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="UserControlContent" Storyboard.TargetProperty="(Content).Children[0].(UIElement.Visibility)"> <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border Background="{TemplateBinding Background}"/> <ContentPresenter x:Name="UserControlContent"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </ContentControl.Resources> <StackPanel x:Name="LayoutRoot"> <TextBlock x:Name="State1" Text="Hello from State1"/> <TextBlock x:Name="State2" Text="Hello from State2"/> </StackPanel> </ContentControl>
|
Теперь то что называется Code Behind:
| Код | namespace TestVSM { [TemplateVisualState(GroupName = "MyGroup", Name = "State1")] [TemplateVisualState(GroupName = "MyGroup", Name = "State2")] public partial class UserControl1 : ContentControl { public UserControl1() { InitializeComponent();
this.LayoutUpdated += new EventHandler(UserControl1_LayoutUpdated); }
void UserControl1_LayoutUpdated(object sender, EventArgs e) { VisualStateManager.GoToState(this, "State1", false); this.LayoutUpdated -= this.UserControl1_LayoutUpdated; } } }
|
вот.. подскажите что делать?!! |