[UWP] RatingControl更改属性什么都不做? [英] [UWP] RatingControl changing attributes does nothing?

查看:65
本文介绍了[UWP] RatingControl更改属性什么都不做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的UWP应用程序中使用RatingControl。在我的应用程序中,我希望点击时星星的颜色变为黄色,而不是默认的蓝色。我试图在RatingControl上设置前景和背景属性,但这些似乎什么都不做。
同样在设置BorderBrush和BorderThickness时我没有看到任何变化。

I want to use the RatingControl inside my UWP app. In my app I want the color of the stars to turn yellow when clicked instead of the default blue. I have tried to set the foreground and background attribute on the RatingControl but those appear to do nothing. Also when setting the BorderBrush and BorderThickness I don't see any change.

为什么更改这些属性不会做任何事情,如何更改颜色和大小在RatingsControl中的星星?

Why does changing these attributes don't do anything and how can I change the color and size of the stars in a RatingsControl?

推荐答案

嗨  Otto CLausen,

Hi Otto CLausen,

欢迎来到
开发通用Windows应用论坛
!请使用  标记 
发布到此论坛时,谢谢!

如果您只是希望明星的代码在点击时变为黄色,您可以在< VisualState x:Name =" Set"中更改
RatingControl 的样式;> ...作为以下样式,

If you just want the stars' code turn yellow when click, you can change the RatingControl's style in the <VisualState x:Name="Set">... as the following style,

   <Style x:Key="RatingControlStyle1" TargetType="RatingControl">
            <Setter Property="Height" Value="32"/>
            <Setter Property="Foreground" Value="{ThemeResource RatingControlCaptionForeground}"/>
            <Setter Property="UseSystemFocusVisuals" Value="true"/>
            <Setter Property="FontFamily" Value="Segoe MDL2 Assets"/>
            <Setter Property="ItemInfo" Value="{ThemeResource RatingControlDefaultFontInfo}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="RatingControl">
                        <Grid x:Name="LayoutRoot">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Disabled">
                                        <VisualState.Setters>
                                            <Setter Target="ForegroundContentPresenter.Foreground" Value="{ThemeResource RatingControlDisabledSelectedForeground}"/>
                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="Placeholder">
                                        <VisualState.Setters>
                                            <Setter Target="ForegroundContentPresenter.Foreground" Value="{ThemeResource RatingControlPlaceholderForeground}"/>
                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="PointerOverPlaceholder">
                                        <VisualState.Setters>
                                            <Setter Target="ForegroundContentPresenter.Foreground" Value="{ThemeResource RatingControlPointerOverPlaceholderForeground}"/>
                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="PointerOverUnselected">
                                        <VisualState.Setters>
                                            <Setter Target="ForegroundContentPresenter.Foreground" Value="{ThemeResource RatingControlPointerOverUnselectedForeground}"/>
                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="Set">
                                        <VisualState.Setters>
                                            <Setter Target="ForegroundContentPresenter.Foreground" Value="Yellow"/>
                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="PointerOverSet">
                                        <VisualState.Setters>
                                            <Setter Target="ForegroundContentPresenter.Foreground" Value="{ThemeResource RatingControlSelectedForeground}"/>
                                        </VisualState.Setters>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <StackPanel Margin="-20,-20,-20,-20" Orientation="Horizontal" Grid.Row="0">
                                <StackPanel x:Name="RatingBackgroundStackPanel" Background="Transparent" Margin="20,20,0,20" Orientation="Horizontal"/>
                                <TextBlock x:Name="Caption" AutomationProperties.AccessibilityView="Raw" Height="32" IsHitTestVisible="False" Margin="4,9,20,0" AutomationProperties.Name="RatingCaption" Style="{ThemeResource CaptionTextBlockStyle}" TextLineBounds="TrimToBaseline" Text="{TemplateBinding Caption}" VerticalAlignment="Center"/>
                            </StackPanel>
                            <ContentPresenter x:Name="ForegroundContentPresenter" IsHitTestVisible="False" Grid.Row="0">
                                <StackPanel Margin="-40,-40,-40,-40" Orientation="Horizontal">
                                    <StackPanel x:Name="RatingForegroundStackPanel" IsHitTestVisible="False" Margin="40,40,40,40" Orientation="Horizontal"/>
                                </StackPanel>
                            </ContentPresenter>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

您仍然可以更改其他  VisualState以满足您的要求。

You can still change other VisualState to satisfy your requirement.

但对于明星而言大小,它应该是非常复杂的,星星和星星的填充是在代码中实现的,如下面的实时可视树图像,

But for the star size, it should be much complex, the stars and stars's fill are implement in the code, as the following Live visual tree image,

它有10个TextBlocks渲染星星和星星的填充,我们应该在后面的代码中获取文本块并修改它们的FontSize,同时,我们仍然需要
重新定位星星位置,这是一项艰苦的工作,你可以尝试一下。

It has 10 TextBlocks to render the stars and star's fill, we should get the textblocks in the code behind and modify their FontSize, meanwhile, we still need to re-position the stars position, it is a hard work, you can have a try.

祝你好运,

Breeze


这篇关于[UWP] RatingControl更改属性什么都不做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆