如何将按钮的可见性绑定到ViewModel中的bool值?
<Button Height="50" Width="50" Style="{StaticResource MyButtonStyle}"
Command="{Binding SmallDisp}" CommandParameter="{Binding}" Cursor="Hand"
Visibility="{Binding Path=AdvancedFormat}" />
Run Code Online (Sandbox Code Playgroud) 这可能是一个没有脑子的人,但我似乎无法让它发挥作用.我有一个视图模型暴露了一个名为bool NotFound的属性我想将它绑定到一个触发器,以便当它更改我的控件上的图像更改时.
这是我用作其中一个视图模型的数据模板的xaml.
<DataTemplate DataType="{x:Type local:TabFileViewModel}">
<StackPanel Orientation="Horizontal">
<Image Width="16" Height="16" Margin="3,0" Source="Image\TabFile.PNG" />
<TextBlock Text="{Binding Name}" ToolTip="{Binding FullPath}"/>
</StackPanel>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
我希望能够绑定到NotFound属性并更改图像源.
谢谢.
弥敦道
我有一个列表视图,它显示项目名称和每个项目的一些按钮,这些按钮执行不同的操作,例如为该项目添加评论查看图像等。根据项目的不同,某些项目有时会禁用其中一些按钮。并且某些按钮在某些项目中将不可见。所以我想在这段代码中使用数据绑定来实现两件事。
根据 ProjectModel 的一些布尔变量,我需要更改按钮的可见性。我尝试将按钮的可见性绑定到 ViewModel 中的 bool 值,但它似乎不适用于 uwp。
对于某些项目,当禁用该选项时,我需要显示不同的彩色图像。所以我需要根据 ProjectModel 的布尔变量更改 ImageBrush 的 ImageSource。为此,我使用触发器 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"/> …Run Code Online (Sandbox Code Playgroud)