如何将按钮的可见性绑定到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属性并更改图像源.
谢谢.
弥敦道
我正在开发我的第一个UWP应用程序,我希望创建一个这样的UI .对于每个列表项(项目),将有一组按钮.对于某些列表项(项目),某些按钮将被禁用一些.因此,我需要在这些列表项(项目)中禁用和更改此类按钮的图像.
我尝试使用像这样的列表视图来实现它.但我不知道如何根据条件启用/禁用其中一些按钮.
尝试添加DataContextChanged事件并尝试访问那里的按钮.但不知道我如何访问这些按钮.
请告诉我以下方法是否正确,或者是否有更好的方法来完成我在上图中尝试实现的目标.
<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}" …
Run Code Online (Sandbox Code Playgroud)