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?










share|improve this question
























  • 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















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?










share|improve this question
























  • 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













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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy