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. 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
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;
}
}
This can be easily done through XAML instead of code behind using Behaviours
Behaviors SDK is not built-in UWP, but has to be downloaded separately from NuGet.
Install the NuGet Package for Microsoft.Xaml.Behaviors.Uwp.Managed
.
After you install, you can just add the XAML using statements to the top of your page:
<Page ...
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core" />
and change your Header_p
to below.
<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.
private void Header_P(object sender, TappedRoutedEventArgs e)
{
var colorBrush = chkColor.Fill as SolidColorBrush;
if (colorBrush != null)
{
colorimg.Foreground = new SolidColorBrush(colorBrush.Color);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.