UWP VisualStateManager.GotoState works not correctly
up vote
1
down vote
favorite
I have a custom control MediaPlayerControl
. In the its Template I define a VisualStateGroup
:
<VisualStateGroup x:Name="SizeState">
<VisualState x:Name="Normal" />
<VisualState x:Name="LargeSize" >
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaInfo_Border" Storyboard.TargetProperty="(Grid.ColumnSpan)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaInfo_Border" Storyboard.TargetProperty="(Grid.RowSpan)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PrimaryMediaControl_Border" Storyboard.TargetProperty="HorizontalAlignment" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaTransportControls_Timeline_Border" Storyboard.TargetProperty="(Grid.Column)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaTransportControls_Timeline_Border" Storyboard.TargetProperty="(Grid.ColumnSpan)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MoreButton" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="SecondaryTrim_MenuFlyOut" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="TrimButton" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
And in the SizeChanged
event I call ChangeState()
function:
private void MediaPlayerControl_SizeChanged(object sender, object e)
{
ChangeState();
}
private void ChangeState()
{
string state = "";
if (Window.Current.Bounds.Width < 600)
{
state = "Normal";
}
else
{
state = "LargeSize";
}
VisualStateManager.GoToState(this, state, false);
}
Although VisualStateManager.GoToState
return true
and UI change to LargeSize
state but in short time it automatically changes to Normal
state.
If I use LayoutUpdated
event, it work properly, but performance is not good.
Can I use GotoState
with SizeChanged
event?
c# uwp visualstatemanager
add a comment |
up vote
1
down vote
favorite
I have a custom control MediaPlayerControl
. In the its Template I define a VisualStateGroup
:
<VisualStateGroup x:Name="SizeState">
<VisualState x:Name="Normal" />
<VisualState x:Name="LargeSize" >
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaInfo_Border" Storyboard.TargetProperty="(Grid.ColumnSpan)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaInfo_Border" Storyboard.TargetProperty="(Grid.RowSpan)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PrimaryMediaControl_Border" Storyboard.TargetProperty="HorizontalAlignment" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaTransportControls_Timeline_Border" Storyboard.TargetProperty="(Grid.Column)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaTransportControls_Timeline_Border" Storyboard.TargetProperty="(Grid.ColumnSpan)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MoreButton" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="SecondaryTrim_MenuFlyOut" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="TrimButton" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
And in the SizeChanged
event I call ChangeState()
function:
private void MediaPlayerControl_SizeChanged(object sender, object e)
{
ChangeState();
}
private void ChangeState()
{
string state = "";
if (Window.Current.Bounds.Width < 600)
{
state = "Normal";
}
else
{
state = "LargeSize";
}
VisualStateManager.GoToState(this, state, false);
}
Although VisualStateManager.GoToState
return true
and UI change to LargeSize
state but in short time it automatically changes to Normal
state.
If I use LayoutUpdated
event, it work properly, but performance is not good.
Can I use GotoState
with SizeChanged
event?
c# uwp visualstatemanager
I would guess that there are some other trigger which makes your UI go back to normal state but I have no idea what it is. Can you provide more details about your project, like a demo or share us the steps about how we can reproduce this issue?
– Barry Wang - MSFT
yesterday
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a custom control MediaPlayerControl
. In the its Template I define a VisualStateGroup
:
<VisualStateGroup x:Name="SizeState">
<VisualState x:Name="Normal" />
<VisualState x:Name="LargeSize" >
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaInfo_Border" Storyboard.TargetProperty="(Grid.ColumnSpan)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaInfo_Border" Storyboard.TargetProperty="(Grid.RowSpan)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PrimaryMediaControl_Border" Storyboard.TargetProperty="HorizontalAlignment" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaTransportControls_Timeline_Border" Storyboard.TargetProperty="(Grid.Column)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaTransportControls_Timeline_Border" Storyboard.TargetProperty="(Grid.ColumnSpan)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MoreButton" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="SecondaryTrim_MenuFlyOut" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="TrimButton" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
And in the SizeChanged
event I call ChangeState()
function:
private void MediaPlayerControl_SizeChanged(object sender, object e)
{
ChangeState();
}
private void ChangeState()
{
string state = "";
if (Window.Current.Bounds.Width < 600)
{
state = "Normal";
}
else
{
state = "LargeSize";
}
VisualStateManager.GoToState(this, state, false);
}
Although VisualStateManager.GoToState
return true
and UI change to LargeSize
state but in short time it automatically changes to Normal
state.
If I use LayoutUpdated
event, it work properly, but performance is not good.
Can I use GotoState
with SizeChanged
event?
c# uwp visualstatemanager
I have a custom control MediaPlayerControl
. In the its Template I define a VisualStateGroup
:
<VisualStateGroup x:Name="SizeState">
<VisualState x:Name="Normal" />
<VisualState x:Name="LargeSize" >
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaInfo_Border" Storyboard.TargetProperty="(Grid.ColumnSpan)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaInfo_Border" Storyboard.TargetProperty="(Grid.RowSpan)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PrimaryMediaControl_Border" Storyboard.TargetProperty="HorizontalAlignment" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaTransportControls_Timeline_Border" Storyboard.TargetProperty="(Grid.Column)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MediaTransportControls_Timeline_Border" Storyboard.TargetProperty="(Grid.ColumnSpan)" >
<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MoreButton" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="SecondaryTrim_MenuFlyOut" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="TrimButton" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
And in the SizeChanged
event I call ChangeState()
function:
private void MediaPlayerControl_SizeChanged(object sender, object e)
{
ChangeState();
}
private void ChangeState()
{
string state = "";
if (Window.Current.Bounds.Width < 600)
{
state = "Normal";
}
else
{
state = "LargeSize";
}
VisualStateManager.GoToState(this, state, false);
}
Although VisualStateManager.GoToState
return true
and UI change to LargeSize
state but in short time it automatically changes to Normal
state.
If I use LayoutUpdated
event, it work properly, but performance is not good.
Can I use GotoState
with SizeChanged
event?
c# uwp visualstatemanager
c# uwp visualstatemanager
edited Nov 17 at 5:55
asked Nov 17 at 5:40
Linh Nguyen Huy
115
115
I would guess that there are some other trigger which makes your UI go back to normal state but I have no idea what it is. Can you provide more details about your project, like a demo or share us the steps about how we can reproduce this issue?
– Barry Wang - MSFT
yesterday
add a comment |
I would guess that there are some other trigger which makes your UI go back to normal state but I have no idea what it is. Can you provide more details about your project, like a demo or share us the steps about how we can reproduce this issue?
– Barry Wang - MSFT
yesterday
I would guess that there are some other trigger which makes your UI go back to normal state but I have no idea what it is. Can you provide more details about your project, like a demo or share us the steps about how we can reproduce this issue?
– Barry Wang - MSFT
yesterday
I would guess that there are some other trigger which makes your UI go back to normal state but I have no idea what it is. Can you provide more details about your project, like a demo or share us the steps about how we can reproduce this issue?
– Barry Wang - MSFT
yesterday
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348571%2fuwp-visualstatemanager-gotostate-works-not-correctly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I would guess that there are some other trigger which makes your UI go back to normal state but I have no idea what it is. Can you provide more details about your project, like a demo or share us the steps about how we can reproduce this issue?
– Barry Wang - MSFT
yesterday