在列表框中选择复选框时改变文本框的颜色c# wpf



我有一个列表框,每个元素有3个按钮,2个文本框和一个复选框。

我想为按钮和文本框改变属性(颜色/或其他),当我检查复选框。

希望有人能帮助我:)

谢谢你的回答…

<!-- LISTBOX -->
<ListBox Name="lstBoxInfoWindow" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Foreground="Black" ScrollViewer.VerticalScrollBarVisibility="Visible" Margin="5,1.2,4.6,-0.4" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="Black"/>
</Trigger>
<Trigger Property=""
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Name="btnPackageVersion" Content ="Package version" Click="btnPackageVersion_Click" HorizontalAlignment="Right" Margin="10,0,10,0">
</Button>
<Button Name="btnFilterPath" Content ="Filter path" Click="btnFilterpath_Click" HorizontalAlignment="Right"/>
<TextBlock Name="txtBlkPath" Text="{Binding path, Mode=TwoWay}" FontSize="10" Width="500" Height="20" Margin="10,0,10,0"/>
<Button Name="btnFilterfile" Content="Filter file" Click="btnFilterfile_Click" HorizontalAlignment="Right"/>
<TextBlock Name="txtBlkFile" Text="{Binding file, Mode=TwoWay}" FontSize="10" Width="150" Height="20" Margin="10,0,10,0"/>
<CheckBox Name="chkBxKill" Content="Kill" VerticalAlignment="Center" HorizontalAlignment="Right" IsChecked="{Binding keepKill.kill, Mode=TwoWay}" Margin="5,0,5,0" Checked="chkBxKill_Checked"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
</Grid>
</Window>

使用DataTemplate中定义的DataTrigger

以下示例设置按钮的Backgound为红色,当CheckBox被选中时:

<DataTemplate>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Right">
...
<Button Name="btnFilterfile" />    
<CheckBox Name="chkBxKill" />
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding ElementName=chkBxKill, Path=IsChecked}" Value="True">
<Setter TargetName="btnFilterfile" Property="Background" Value="Red" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>

相关内容

  • 没有找到相关文章

最新更新