C# GridView和StackPanel内的UWP情节提要
因此,我有一个数据绑定的网格视图,我希望StackPanel(statestackPanel)的背景色在特定条件下呈橙色闪烁。现在我用绑定转换器将背景色设置为橙红色。在同样的条件下,我宁愿背景色从橙红色闪烁到黑色。这可能吗C# GridView和StackPanel内的UWP情节提要,c#,xaml,uwp,C#,Xaml,Uwp,因此,我有一个数据绑定的网格视图,我希望StackPanel(statestackPanel)的背景色在特定条件下呈橙色闪烁。现在我用绑定转换器将背景色设置为橙红色。在同样的条件下,我宁愿背景色从橙红色闪烁到黑色。这可能吗 <GridView x:Name="grdViewZones" ItemsSource="{Binding _zoneData.Zones}" Canvas.Top="91" Canvas.Left="25" VerticalAlignment="Center" Hor
<GridView x:Name="grdViewZones" ItemsSource="{Binding _zoneData.Zones}" Canvas.Top="91" Canvas.Left="25" VerticalAlignment="Center" HorizontalAlignment="Left">
<GridView.ItemTemplate>
<DataTemplate x:Name="ImageTextDataTemplate" x:DataType="jsonObjects:WaveSorterZoneModel">
<StackPanel Height="330" Width="330" Margin="12,12,12,12">
<Grid x:Name="grdZoneLayout" Height="250" Width="330" BorderBrush="{Binding Converter={StaticResource ItemToColorConverter}}" BorderThickness="10">
<TextBlock Text="{x:Bind RSID, Mode=OneWay}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="70"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="{x:Bind ZoneDescription}" Style="{ThemeResource CaptionTextBlockStyle}" FontSize="16">
<TextBlock.Foreground>
<SolidColorBrush Color="{ThemeResource SystemBaseHighColor}"/>
</TextBlock.Foreground>
</TextBlock>
<TextBlock Text=" :" Style="{ThemeResource CaptionTextBlockStyle}" FontSize="16">
<TextBlock.Foreground>
<SolidColorBrush Color="{ThemeResource SystemBaseHighColor}"/>
</TextBlock.Foreground>
</TextBlock>
<TextBlock Text="{x:Bind ZoneNumber, Mode=OneWay}" Margin="10,0,0,0" Style="{ThemeResource CaptionTextBlockStyle}" FontSize="16">
<TextBlock.Foreground>
<SolidColorBrush Color="{ThemeResource SystemBaseHighColor}"/>
</TextBlock.Foreground>
</TextBlock>
</StackPanel>
<StackPanel x:Name="StateStackPanel" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Background="{Binding Converter={StaticResource StateColorConverter}}">
<TextBlock Text="State: " Style="{ThemeResource CaptionTextBlockStyle}" FontSize="20">
<TextBlock.Foreground>
<SolidColorBrush Color="{ThemeResource SystemBaseMediumHighColor}"/>
</TextBlock.Foreground>
</TextBlock>
<TextBlock Text="{x:Bind State, Mode=OneWay}" Margin="10,0,0,0" Style="{ThemeResource CaptionTextBlockStyle}" FontSize="20">
<TextBlock.Foreground>
<SolidColorBrush Color="{ThemeResource SystemBaseMediumHighColor}"/>
</TextBlock.Foreground>
</TextBlock>
</StackPanel>
</Grid>
<!--<TextBlock Text="{Binding RSID}" FocusVisualPrimaryBrush="Black"/>-->
<StackPanel Margin="0,12">
<TextBlock Text="{x:Bind Description, Mode=OneWay}" FocusVisualPrimaryBrush="Black" FontSize="24" TextWrapping="Wrap"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid MaximumRowsOrColumns="5" Orientation="Horizontal"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
你的意思是,如果项目满足转换中的条件,你想使用故事板使堆栈面板从橙红色闪烁为黑色吗?是的,我想能够使堆栈面板闪烁。我不一定要在convert方法中使用它,只是想知道如何才能做到这一点。我发现的所有其他示例都是针对静态控件的,而不是通过中继器生成的控件。
public class StateColorConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, string language)
{
var zone = (ZoneModel)value;
if (zone.State == "Stopped" && zone.RSID == "")
{
return new SolidColorBrush(Colors.OrangeRed);
}
else
{
return new SolidColorBrush(Colors.Black);
}
}
//you don't have to implement conversion back as this is just one-way binding
public object ConvertBack(object value, Type targetType,
object parameter, string language)
{
throw new NotImplementedException();
}
}