wpf mvvm visualstate manager在加载之前改变状态

时间:2017-05-17 07:30:27

标签: wpf mvvm visualstatemanager

我想在加载控件之前更改状态。我必须在加载事件或更晚时更改状态,但usercontrol没有contentRendered事件。有没有解决方案。

这里是我的代码:

查看:

<VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="MyStateGroup">

            <VisualState x:Name="CameraConnected">
                <Storyboard>
                    <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="label">
                        <EasingColorKeyFrame KeyTime="0" Value="#FF0EE603"/>
                    </ColorAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ContentControl.Content)" Storyboard.TargetName="label">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="StaticResource Connected}"/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <VisualState x:Name="BaseState"></VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

视图模型:

    private bool _isConnected = false;
    public const string IsConnectedPropertyName = "IsConnected";

    public bool IsConnected
    {
        get
        {
            return _isConnected;
        }
        set
        {
            if (_isConnected == value)
            {
                return;
            }
            _isConnected = value;
            RaisePropertyChanged(IsConnectedPropertyName);
        }
    }
    internal void userControl_Loaded()
    {
        IsConnected = true;
    }

感谢您的帮助。

0 个答案:

没有答案