我是WPF的初學者,我嘗試用DataTrigger編寫WPF部分。Setter Target Name not recognized
這裏所需要的邏輯:
If the variable "iBottleCount" >= 10 then make the background of a label green. If the variable "iBottleCount" < 10 then make the background of a label yellow. If the variable "iBottleCount" = 0 then make the background of a label red.
但他can'f發現我與targed名 「StatusColor」 的標籤。
找到下面的代碼:
<DataGridTemplateColumn Header="Status" Width="80" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="StatusText" Height="15" HorizontalAlignment="Left" Margin="2,2,2,2" Text="" VerticalAlignment="Top" Grid.Row="0" Grid.Column="1"/>
<Label x:Name="StatusColor" Content="" Background="green" HorizontalAlignment="Center" Margin="5,5,5,5" VerticalAlignment="Top" Height="10" Width="20" Grid.Row="0" Grid.Column="0"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<DataTrigger Binding="{Binding iBottleCount}" Value="=>10">
<!-- PROBLEM IS IN THIS LINE -->
<Setter TargetName="StatusColor" Property="Background" Value="Green" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTemplateColumn.CellStyle>
</DataGridTemplateColumn>
那麼,有什麼問題呢?標籤被定義爲更高的一些行。
我認爲你的錯誤可能在這裏: 10」> 嘗試輸入:Value> =「10」 –