我有两个文本块和一个按钮的 ListBox。默认情况下,按钮的可见性是折叠的。
列表框
<ListBox x:Name="companiesList" Height="{Binding ActualHeight, ElementName=ContentPanel}" SelectionChanged="companiesList_SelectionChanged" ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid x:Name="listItem" Background="{Binding BackgroundBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="35"/>
<RowDefinition Height="40"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<StackPanel x:Name="namePanel" Grid.Row="0" Orientation="Horizontal" Margin="5,0,0,0" Height="50">
<TextBlock x:Name="nameTextBlock" Text="{Binding CompanyName}" Foreground="#FF501F6E" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="28" MaxHeight="50" TextTrimming="WordEllipsis" Margin="0,0,0,0" Width="460" FontWeight="Bold" FontFamily="Fonts/Riwaj.ttf#Riwaj"/>
</StackPanel>
<StackPanel x:Name="addressPanel" Grid.Row="1" Orientation="Horizontal" Margin="5,-5,0,5" Height="35">
<TextBlock x:Name="addressTextBlock" Text="{Binding Address}" Foreground="#FF1F1F1F" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="20" MaxHeight="35" TextTrimming="WordEllipsis" Margin="0,0,0,0" Width="460" FontFamily="Fonts/Riwaj.ttf#Riwaj"/>
</StackPanel>
<StackPanel x:Name="phonePanel" Grid.Row="2" Orientation="Horizontal" Margin="5,0,0,0" Height="35">
<Button x:Name="sponseredButton" Style ="{StaticResource ButtonStyleIB}" HorizontalAlignment="Right" Click="spon_button_clicked" Width="Auto" Height="Auto" Visibility="Collapsed">
<Image x:Name="sponseredButtonImage" Source="{Binding SponseredImageSource}" Stretch="None" />
</Button>
</StackPanel>
<Image x:Name="line" Grid.Row="3" Width="460" HorizontalAlignment="Center" Source="Images/separator.png" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
现在在文件(.cs 文件)后面的代码中,我想根据某些条件更改按钮的可见性。
请帮助我如何做到这一点。