I have some VisualStates and I want to Change the AdaptiveTrigger
MinWindowWidth
in the Code behind in a if statment.
VisualState:
<VisualState x:Name="VisualState">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="1100"/>
</VisualState.StateTriggers>
....
</VisualState>
and in the Code behind it should look like this:
if (Something == true)
{
VisualState1.SetValue(AdaptiveTrigger.MinWindowWidthProperty, 1370);
}
I don't know why but it doesn't work and so I hope you can help me.
答案 0 :(得分:1)
Refering to the VisualState
itself won't do the job. The property you are refering to belongs to the AdaptiveTrigger
.
<VisualState x:Name="VisualState">
<VisualState.StateTriggers>
<!-- For better reference in code behind, include VisualState name -->
<AdaptiveTrigger x:Name="TriggerOfVisualState"
MinWindowWidth="1100"/>
</VisualState.StateTriggers>
....
</VisualState>
Please note:
The way you are setting the new value acts like setting an attached property.
You should only set them like this, if the property is actually an attached property (e.g. Grid.Row
).
Otherwise use the direct property accessor:
TriggerOfVisualState.MinWindowWidth = 1370;
答案 1 :(得分:0)
This should do it:
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger x:Name="MyTrigger" MinWindowWidth="1100"/>
</VisualState.StateTriggers>
....
</VisualState>
and code-behind:
MyTrigger.MinWindowWidth = 1370;
If you use MVVM or some other data binding, you can also use {Binding myMinWidth}
for the MinWindowWidth
property value.