我正在尝试将字符串格式的颜色转换为在开关盒中使用,以检查填充椭圆的颜色,并根据我想要填充ttf图标中的颜色。在“Header_P”的Tapped事件上,我想检查填充Ellipse“chkColor”的颜色并使用相同的颜色,我想填充“colorimg”ttf图标,颜色相同
的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
private void Header_P(object sender, TappedRoutedEventArgs e)
{
string colorn = chkColor.GetValue();
switch ()
{
default:
break;
}
}
答案 0 :(得分:1)
这可以通过XAML轻松完成,而不是使用行为
后面的代码Behaviors SDK不是内置的UWP,但必须与NuGet分开下载。
为Microsoft.Xaml.Behaviors.Uwp.Managed
安装NuGet包。
安装后,您只需将XAML using语句添加到页面顶部:
<Page ...
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core" />
并将您的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>
答案 1 :(得分:0)
如果它是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);
}
}