No, you don't have Trigger
support in UWP.
A workaround is to use DataTriggerBehavior
with a ChangePropertyAction
to accomplish the exact same thing.
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
<Button x:Name="MyButton" Width="140" Height="80" IsEnabled="False">
<Image x:Name="MyImage" Source="Assets/xxx.jpg">
<Interactivity:Interaction.Behaviors>
<Core:DataTriggerBehavior Binding="{Binding IsEnabled, ElementName=MyButton}" Value="False">
<Core:ChangePropertyAction TargetObject="{Binding ElementName=MyImage}" PropertyName="Opacity" Value="0.5" />
</Core:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</Image>
</Button>
Note that you will need to include BehaviorsXamlSDKManaged
from C:Program Files (x86)Microsoft SDKsWindowsv8.1ExtensionSDKsBehaviorsXamlSDKManaged12.0
. You will get a warning when you add the reference but just ignore it.
Update:
You should be getting an updated Behavior SDK from nuget now.
Option 2
You can always do the same thing in VisualStateManager
. Open Blend and right click on your Button
and select Edit Template, Edit a Copy and then specify the resource name you want and hit OK.
Then look for the Disabled VisualState
and replace it with
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Target="RootGrid.(UIElement.Opacity)" Value="0.5" />
</VisualState.Setters>
</VisualState>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…