[英]Trying to convert color in string format t use in switch case
I'm trying to convert color in string format to use in switch case to check the color which is filled in ellipse and based on that i want to fill the color in ttf icon. 我正在尝试将颜色转换为字符串格式以用于切换情况下,以检查椭圆形填充的颜色,并基于此我想在ttf图标中填充颜色。 On Tapped Event of"Header_P" i want to check the color with which Ellipse "chkColor" is filled and with same color i want to fill "colorimg" ttf icon with same color
在“ Header_P”事件中,我想检查椭圆“ chkColor”被填充的颜色,并用相同的颜色,我想用相同的颜色填充“ colorimg” ttf图标
Xaml Xaml
<Image x:Name="Header_P"
Source="Assets/Paint/bg_paint_sub.png"
Height="250" Width="600"
RelativePanel.AlignHorizontalCenterWithPanel="True"
Margin="0,60,40,0"
Opacity="0.8"
Tapped="Header_P"
/>
<Ellipse x:Name="chkColor" Height="40" Width="40"
RelativePanel.AlignHorizontalCenterWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
Margin="0,140,235,0"></Ellipse>
<TextBlock x:Name="colorimg"
Text="0" TextAlignment="Center"
RelativePanel.AlignHorizontalCenterWithPanel="True"
FontFamily="Font/fill-icons.ttf#fill-icons"
FontSize="170"
Margin="0,90,50,0"/>
c# code C#代码
private void Header_P(object sender, TappedRoutedEventArgs e)
{
string colorn = chkColor.GetValue();
switch ()
{
default:
break;
}
}
This can be easily done through XAML instead of code behind using Behaviours 这可以通过XAML轻松完成,而不是使用Behaviors进行背后的代码
Behaviors SDK is not built-in UWP, but has to be downloaded separately from NuGet. Behaviors SDK不是内置的UWP,但必须与NuGet分开下载。
Install the NuGet Package for Microsoft.Xaml.Behaviors.Uwp.Managed
. 为
Microsoft.Xaml.Behaviors.Uwp.Managed
安装NuGet软件包。
After you install, you can just add the XAML using statements to the top of your page: 安装后,您只需在页面顶部添加XAML using语句即可:
<Page ...
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core" />
and change your Header_p
to below. 并将您的
Header_p
更改为以下内容。
<Image x:Name="Header_P" Source="Assets/Paint/bg_paint_sub.png" Height="250" Opacity="0.8" >
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="Tapped" SourceObject="{Binding ElementName=chkColor, Mode=OneWay}" >
<Core:EventTriggerBehavior.Actions>
<Core:ChangePropertyAction PropertyName="Foreground" TargetObject="{Binding ElementName=colorimg}" Value="{Binding Fill, ElementName=chkColor}"/>
</Core:EventTriggerBehavior.Actions>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</Image>
This snippet extracts the color from the Brush if it is a SolidColorBrush. 如果是SolidColorBrush,此代码段将从Brush中提取颜色。
private void Header_P(object sender, TappedRoutedEventArgs e)
{
var colorBrush = chkColor.Fill as SolidColorBrush;
if (colorBrush != null)
{
colorimg.Foreground = new SolidColorBrush(colorBrush.Color);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.