Trouble animating a SolidColorBrush - .net-4.0

I have the following code:
<Grid.Background>
<DrawingBrush Stretch="Uniform">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="{Binding Path=SegmentBackground, ElementName=Segment, Mode=OneWay}" x:Name="SegmentDrawing" Geometry="M 278.229,141.688C 278.229,128.798 276.451,116.324 273.128,104.497L 228.906,122.309C 230.417,128.8 231.216,135.565 231.216,142.517C 231.216,147.98 230.723,153.328 229.778,158.518L 275.262,170.2C 277.206,161.002 278.229,151.464 278.229,141.688 Z ">
<GeometryDrawing.Pen>
<Pen LineJoin="Round" Brush="#FF000000"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Grid.Background>
My question is simple, I want to animate the Brush property of the GeometryDrawingBrush.
The drawing is the main visual of my control, and I want the color of the brush to change to reflect it's state (Normal,Over, etc.).

Related

"Shortcut" for Setting ListViewItem Selected Background

I'm using Anniversary Update (14393).
I can use this code to set ListViewItem Background.
<SolidColorBrush x:Name="ListViewItemBackground" Color="AntiqueWhite" />
Is it possible using this technique to set color for ListViewItem Selected/PointOver Background?
Yes, you can override the selected background brush for the ListView, so that it will use your color rather than the default. You do this by providing a ListView resource with the same key defined by the control.
<ListView>
<ListView.Resources>
<SolidColorBrush x:Key="ListViewItemBackgroundSelected" Color="Yellow"/>
<SolidColorBrush x:Key="ListViewItemForegroundSelected" Color="LimeGreen"/>
<SolidColorBrush x:Key="ListViewItemBackgroundSelectedPointerOver" Color="Blue"/>
</ListView.Resources>
</ListView>
UWP defines global brushes for all of its controls to make theming easy. By setting the resource within the ListView.Resources collection, these changes only affect this instance of the ListView.
If you want to set the same color scheme for the page or the entire app, you can override these brushes either in the Page or App resource dictionaries.

canvas bottom missing uwp

I have a Canvas /RelativePanel which I'm using as background "image" in my uwp app.
How can I position a child in the canvas at the bottom? There is no canvas.bottom AP like in wpf. I also didn't find any proper attached property in the relativepanel to position the child at the bottom of the relative panel.
<RelativePanel>
<ContentControl ContentTemplate="{StaticResource AsterioidTemplate}" />
<Canvas x:Name="mountain_to_bottom" HorizontalAlignment="Stretch" VerticalAlignment="Bottom">
<Path Width="126.389" Height="326.227" Canvas.Left="272.433" Canvas.Top="28.3291" Stretch="Fill" StrokeThickness="1.33333" StrokeLineJoin="Round" Stroke="#FF23232D" Fill="#FF23232D" Data="F1 M 398.155,353.889L 273.099,186.024L 315.298,28.9958L 398.155,353.889 Z "/>
</Canvas>
</RelativePanel>
How can I position a child in the canvas at the bottom?
Canvas is a layout panel that supports absolute positioning of child elements relative to the top left corner of the canvas in uwp.You control the positioning of elements inside the Canvas by specifying x and y coordinates.Since canvas is absolute positioning , child content is not constrained by the bounds of the panel, so we may not define the child at the bottom of canvas directly. But we can try to calculate the position manually to let the child position at the bottom of canvas. For example, the following demo can show the image at the bottom of the canvas.
XAML Code
<Canvas Background="Pink" x:Name="mountain_to_bottom" Height="600">
<Path x:Name="pathelement" Width="126.389" Height="326.227" VerticalAlignment="Bottom" Stretch="Fill" StrokeThickness="1.33333" StrokeLineJoin="Round" Stroke="#FF23232D" Fill="#FF23232D" Data="F1 M 398.155,353.889L 273.099,186.024L 315.298,28.9958L 398.155,353.889 Z "/>
</Canvas>
<Button x:Name="btnbottom" Click="btnbottom_Click" Content="to bottom"></Button>
Code behind
private void btnbottom_Click(object sender, RoutedEventArgs e)
{
double canvasheight = mountain_to_bottom.ActualHeight;
if (pathelement.ActualHeight < canvasheight)
{
double top = canvasheight - pathelement.ActualHeight;
pathelement.SetValue(Canvas.TopProperty, top);
}
}
I also didn't find any proper attached property in the relativepanel to position the child at the bottom of the relative panel.
Inside relative panel, elements are positioned using a variety of attached properties. Relative panel provides RelativePanel.AlignBottomWithPanel attached property for position the child at the bottom of the panel.
<RelativePanel BorderBrush="Gray" BorderThickness="10">
<Path x:Name="pathelement" RelativePanel.AlignBottomWithPanel="True" Width="126.389" Height="326.227" VerticalAlignment="Bottom" Stretch="Fill" StrokeThickness="1.33333" StrokeLineJoin="Round" Stroke="#FF23232D" Fill="#FF23232D" Data="F1 M 398.155,353.889L 273.099,186.024L 315.298,28.9958L 398.155,353.889 Z "/>
</RelativePanel>
If canvas and relative panel can not meet your requirements well you can consider about other containers. What container to use depend on your layout. For example, relativePanel is a layout container that is useful for creating UIs that do not have a clear linear pattern; that is, layouts that are not fundamentally stacked, wrapped, or tabular, where you might naturally use a StackPanel or Grid. More details please reference Layout panels.

SystemAccentColor + Converter

[UWP] I created a SolidColorBrush resource from SystemAccentColor color, I tried to add a converter to lighten the color but it work only at runtime... I see the color lighter but if I go in the settings OS and I change the accent color, it change in other texts while my color with converter doesn't work. Is there a method to "update" my resource when I change the system accent color?
In my app:
<Grid Background="{ThemeResource AuraAccent}"/>
<Grid Background="{ThemeResource AuraAccentLight1}"/>
ResourceDictionary:
<SolidColorBrush x:Key="AuraAccent" Color="{ThemeResource SystemAccentColor}"/>
<SolidColorBrush x:Key="AuraAccentLight1" Color="{Binding Source={ThemeResource SystemAccentColor}, Converter={ThemeResource shade}, ConverterParameter=30}"/>
AuraAccent work in runtime and when I change the accent color.
AuraAccentLight1 work in runtime but doesn't work when I change the accent color.
How actually it work:
http://sharex.lucapatera.it/uploads/2016-08-31_19-34-32.mp4
I went through few of the resource dictionary files and noticed that The Dictionary will be loaded when App Initially Loads. The changes for Actual Theme Resource will be updated but not custom Brushes ( In your case AuraAccentLight1 because it uses a converter).
This is what I did. Instead of creating a ResourceDictionary with a Shade colour which works only once, I bound the second Grid to first grid saying when first Grid's colour change, second Grid Colour also should be updated.
So below is my XAML
<Grid x:Name="grid" Background="{ThemeResource AuraAccent}"/>
<Grid>
<Grid.Background>
<SolidColorBrush Color="{Binding Background.Color, Converter={StaticResource ColorHelper}, ElementName=grid,ConverterParameter=30}" />
</Grid.Background>
</Grid>
Let me know if this Helps.
Inspired by AVK Naidu, I have resolved in this way:
<SolidColorBrush x:Key="AuraAccentLight1" Color="{Binding Color, Source={ThemeResource AuraAccent}, Converter={ThemeResource shade}, ConverterParameter=30}"/>
Thanks to everyone
Final result:
http://sharex.lucapatera.it/uploads/2016-09-10_19-33-45.gif

UAP xaml triggers/data-triggers

I am trying to design a simple tabbed app using universal windows platform (UWP) using Pivot control.
I have customized header that includes other controls than just a textblock. I am targeting to change color of those controls/graphics on selection of particular PivotItem using triggers in xaml. Default color updates on selection & hover only apply on textblock but not on other controls.
I can try binding color of other controls with forecolor of textblock because I cannot find template binding not control template in UWP xaml. binding with textblock will still give less space for customization as I am targeting AccentColor for header controls/graphics which are defined by MSFT in UAP sdk and we can access them as static resource from generic.xaml. e.g. SystemControlBackgroundAccentBrush. I looked in to xaml triggers as MSFT new xaml architecture allows us to define VisualStateGroups and work using AdaptiveTriggers & StateTrigger. I can't find any other type of triggers like datatriggers, eventtriggers nothing...
<PivotItem>
<PivotItem.Header>
<StackPanel Orientation="Horizontal">
<Path Stretch="Uniform"
Fill="{StaticResource PivotForegroundThemeBrush}"
Width="32pt"
Height="32pt"
Data="M0,33.893959L4.4794149,33.893959 4.4794149,44.677959 48.903614,44.677959 48.903614,33.893959 53.333035,33.893959 53.333035,49.104958 0,49.104958z M24.842734,0L28.513577,0 28.513577,24.615005 35.345016,17.78297 40.346104,17.78297 40.436089,17.883007 26.673088,31.644001 24.072548,29.047991 12.910089,17.883007 13.010208,17.78297 18.001283,17.78297 24.842734,24.615005z"/>
<TextBlock Text="Downloads"
VerticalAlignment="Center" Margin="5"
FontSize="{StaticResource PivotHeaderItemFontSize}"/>
</StackPanel>
</PivotItem.Header>
<Grid></Grid>
</PivotItem>

How to set a background to a textBlock that changes its content

Background
I'm trying to put a textBlock control at the bottom of the screen (with a small margin below it), and I also wish to set a background for it, so that no matter what is shown behind the textBlock, it will be easy to read.
On Android, you could simply set the background to it, and tell it to have the width and height to be WRAP_CONTENT, so that it will take only the space it needs, but I can't find a similar thing on WP8.
Current status
This is the xaml I've created:
...
<Grid >
<Image x:Name="fullScreenImage" Stretch="Fill"
Visibility="Collapsed" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Bottom"
Margin="0,0,0,200" FontSize="40" x:Name="pictureLabel" TextWrapping="Wrap"
Foreground="#ff000000" />
</Grid>
The problem
Since the textBlock doesn't have a background property, I had to use something that wraps it. However, since its content changes dynamically, I can't simply set a size for it.
The question
For now, I would like to simply set its background color.
I would also very appreciate if it would be possible to use a rounded corners rectangle for the background, or a 9-patch image.
How can I achieve setting a background for the textBlock?
The solution is very simple. Just set the HirizontalAlignment to Left. Hope this will work in your case.
<StackPanel HorizontalAlignment="Left">
<Border Background="#66FFFFFF">
<TextBlock/>
</Border>
</StackPanel>
According to this question (which is for Silverlight - but is xaml nonetheless), there is no way to explicitly set a background color for a TextBlock. Your best bet is to wrap your TextBlock in a Grid or Border.
If a Grid does not work, this article suggests a Border will do the trick:
A simple border will do, and by not setting its width and height
properties, it will shrink/grow based on the size of the TextBlock.
I've come up with the next solution , which works quite fine , but what i really would like to also have is a way to set a min font and max font size , so that if there is a single word , the font might need to be of some size, and if the text is too long , the font will be of a smaller size , all in a dynamic way.
code:
label.Text = label;
label.Measure(new Size(RenderSize.Width, RenderSize.Height));
border.Width = label.DesiredSize.Width + border.Padding.Left + border.Padding.Right + border.BorderThickness.Left + border.BorderThickness.Right;
border.Height = label.DesiredSize.Height + border.Padding.Top + border.Padding.Bottom + border.BorderThickness.Bottom + border.BorderThickness.Top;
and the xaml:
<Border BorderBrush="#ff000000" BorderThickness="2" CornerRadius="8" Visibility="Collapsed" Padding="5" Background="#bfff0000" Margin="10,0,10,200" VerticalAlignment="Bottom" x:Name="border">
<StackPanel>
<TextBlock FontSize="40" x:Name="pictureLabel" TextWrapping="Wrap" Foreground="#ff000000" />
</StackPanel>
</Border>