Hello,
Welcome to our Microsoft Q&A platform!
lets say inside the contentview where I have the ViewModel binded and DataType set (x:DataType"ViewModels:MyViewModel"),
Firstly, I add following styles in Application.Resources
, for testing, I set the Frame's background to red, BorderColor to Green.
<Application.Resources>
<Style x:Key="ProductFrame" TargetType="{x:Type Frame}">
<Style.Triggers>
<DataTrigger TargetType="{x:Type Frame}" Binding="{Binding TestProperty}" Value="True">
<Setter Property="BackgroundColor" Value="Red"/>
<Setter Property="BorderColor" Value="Green"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Application.Resources>
Then I create a contentView called View1.Xaml
.
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App27"
x:Class="App27.View1">
<ContentView.Content>
<StackLayout x:DataType="local:MyViewModelColor">
<StackLayout.BindingContext>
<local:MyViewModelColor />
</StackLayout.BindingContext>
<Frame Padding="24" CornerRadius="0" Style="{StaticResource ProductFrame}">
<Label Text="Welcome to Xamarin.Forms!" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
</Frame>
</StackLayout>
</ContentView.Content>
</ContentView>
MyViewModelColor.cs
just have a property called TestProperty
that used in ProductFrame
's style.
It worked, here is my running screenshot.
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.