GridView和StackPanel中的UWP故事板

时间:2018-03-19 02:17:59

标签: c# xaml uwp

所以我有一个数据绑定网格视图,我希望StackPanel(statestackPanel)的背景颜色在某种条件下闪烁橙色。现在我正在使用绑定转换器将背景颜色设置为橙红色。在相同的条件下,我宁愿让背景颜色从橙红色变为黑色。这可能吗?

<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>

C#绑定转换器代码

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();
    }
}

0 个答案:

没有答案