我有一个列表视图,其中显示项目名称和一些按钮为每个项目做不同的动作,如添加评论查看该项目的图像等。根据项目一些项目将有些按钮有时会禁用某些按钮。有些项目中某些按钮不可见。所以在这段代码中我想使用数据绑定来实现两件事情。UWP应用程序显示/隐藏按钮使用绑定
根据ProjectModel的一些布尔变量,我需要更改按钮的可见性。我试过这个Binding a Button's visibility to a bool value in ViewModel,但它似乎不适用于uwp。
对于某些项目,当该选项被禁用时,我需要显示不同的彩色图像。所以我需要根据ProjectModel的布尔变量来更改ImageBrush的ImageSource。为此,我尝试了这个Change image using trigger WPF MVVM,这些样式触发器不适用于uwp。
请让我知道如何在UWP应用程序中轻松完成这些操作。这是我的第一个UWP应用程序,我对这些概念很陌生。
<ListView x:Name="stepsListView" Margin="10,0,0,0" RequestedTheme="Dark" FontSize="24" Background="{StaticResource procedure_app_white}" Foreground="Black" BorderThickness="1.5" BorderBrush="Transparent" ItemsSource="{Binding projectList}" HorizontalAlignment="Left">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<!-- Item -->
<ListView.ItemTemplate>
<DataTemplate>
<Border BorderThickness="0,0,0,1" BorderBrush="#c0c0c0">
<Grid Width="auto" HorizontalAlignment="Stretch" DataContextChanged="Grid_DataContextChanged" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center" FontSize="30" Grid.Row="0" Grid.ColumnSpan="7" Text="{Binding projectName}" Foreground="{StaticResource procedure_app_orange_text }" />
<Button x:Name="warningButton" Width="40" Height="40" Grid.Column="1" Grid.Row="1" Tag="{Binding projectId}" Click="warningButtonClick" Foreground="{StaticResource procedure_app_orange_text }">
<Button.Background>
<ImageBrush ImageSource="Asset/step_ncwr.png">
</ImageBrush>
</Button.Background>
</Button>
<Button x:Name="commentButton" Width="40" Height="40" Grid.Column="2" Grid.Row="1" Tag="{Binding projectId}" Click="CommentButtonClick" Foreground="{StaticResource procedure_app_orange_text }" IsTapEnabled="True">
<Button.Background>
<ImageBrush ImageSource="Asset/step_comment.png">
</ImageBrush>
</Button.Background>
</Button>
<Button x:Name="imageButton" Width="40" Height="40" Grid.Column="3" Grid.Row="1" Tag="{Binding projectId}" Click="ImageButtonClick" Foreground="{StaticResource procedure_app_orange_text }">
<Button.Background>
<ImageBrush ImageSource="Asset/step_image.png">
</ImageBrush>
</Button.Background>
</Button>
</Grid>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
所有禁用的图像都是相同的图像吗? –
@AnthonyRussell例如在项目1中,评论按钮将被禁用。所以我需要为评论按钮显示另一个图标,它显示为灰色禁用。在项目2中,图像按钮将被禁用。在项目3中,我需要隐藏评论按钮。等等。我想做两件事。隐藏一些按钮并更改某些按钮的图像。这些将在该项目上有所不同。对于每个按钮,将有两个图像为橙色图像和灰色图像。 – Madhu
你不应该创建一个灰色。只要禁用按钮,它应该灰色缩放您的图像 –