Hi all,
I'm working on a lab to get background sizing and transition accomplished on a couple of rectangle objects using C# to get it done. It seems to be working to some extent, but I haven't figured out how to get the duration settings to work with the property.
Here's what I have so far in Xaml... a simple grid, and a button flyout containing two rectangle objects for entered/exited functionality:
Here's what I have so far in the code behind in C#... just 'Entered' and 'Exited' functions for the rectangles; the functions of which contain the BackgroundSizing/BackgroundTransition code:
I would like to be able to change the 'BackgroundSizing' and 'BackgroundTransition' properties programmatically in C#, but I haven't found enough info on this to get it working. Does anyone have any ideas?
I'm working on a lab to get background sizing and transition accomplished on a couple of rectangle objects using C# to get it done. It seems to be working to some extent, but I haven't figured out how to get the duration settings to work with the property.
Here's what I have so far in Xaml... a simple grid, and a button flyout containing two rectangle objects for entered/exited functionality:
Code:
<Grid x:Name="mg" Width="Auto" Height="Auto" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="g" Width="200" Height="30" Content="Click for Flyout" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Coral">
<Button.Flyout>
<Flyout Placement="Bottom">
<Grid Width="300" Height="150" CornerRadius="7" Background="Beige" HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel Width="Auto" Height="Auto" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="1">
<Border x:Name="b1" Width="150" Height="80" BorderThickness="1" BorderBrush="Transparent" Background="Transparent">
<Border.BackgroundTransition>
<BrushTransition />
</Border.BackgroundTransition>
<Rectangle x:Name="r1" Width="100" Height="30" Fill="DarkGoldenrod" HorizontalAlignment="Center" VerticalAlignment="Center" PointerEntered="{x:Bind Entered}" PointerExited="{x:Bind Exited}"></Rectangle>
</Border>
<Border x:Name="b2" Width="150" Height="80" BorderThickness="1" BorderBrush="Transparent" Background="Transparent">
<Border.BackgroundTransition>
<BrushTransition />
</Border.BackgroundTransition>
<Rectangle x:Name="r2" Width="100" Height="30" Fill="PaleVioletRed" HorizontalAlignment="Center" VerticalAlignment="Center" PointerEntered="{x:Bind Entered}" PointerExited="{x:Bind Exited}"></Rectangle>
</Border>
</StackPanel>
</Grid>
</Flyout>
</Button.Flyout>
</Button>
</Grid>
Here's what I have so far in the code behind in C#... just 'Entered' and 'Exited' functions for the rectangles; the functions of which contain the BackgroundSizing/BackgroundTransition code:
Code:
public sealed partial class MainWindow
{
public Microsoft.UI.Xaml.Media.Brush Background { get; set; }
public BackgroundSizing BackgroundSizing { get; set; }
public BrushTransition BackgroundTransition { get; set; }
public System.TimeSpan Duration { get; set; }
public void Entered(object sender, RoutedEventArgs e)
{
Microsoft.UI.Xaml.Shapes.Rectangle _r = sender as Microsoft.UI.Xaml.Shapes.Rectangle;
BackgroundSizing bs = new BackgroundSizing();
BrushTransition bt = new BrushTransition();
if (_r == r1)
{
r1.Stroke = new SolidColorBrush(Colors.Purple);
r1.StrokeThickness = 2;
b1.BackgroundSizing = bs;
b1.BackgroundTransition = bt;
b1.Background = new SolidColorBrush(Colors.DarkGray);
}
else if (_r == r2)
{
r2.Stroke = new SolidColorBrush(Colors.Purple);
r2.StrokeThickness = 2;
b2.BackgroundSizing = bs;
b2.BackgroundTransition = bt;
b2.Background = new SolidColorBrush(Colors.DarkGray);
}
else { return; }
}
public void Exited(object sender, RoutedEventArgs e)
{
Microsoft.UI.Xaml.Shapes.Rectangle _r = sender as Microsoft.UI.Xaml.Shapes.Rectangle;
if (_r == r1)
{
b1.Background = new SolidColorBrush(Colors.Transparent);
r1.Stroke = new SolidColorBrush(Colors.Transparent);
r1.StrokeThickness = .5;
}
else if ( _r == r2)
{
b2.Background = new SolidColorBrush(Colors.Transparent);
r2.Stroke = new SolidColorBrush(Colors.Transparent);
r2.StrokeThickness = .5;
}
else { return; }
}
}
I would like to be able to change the 'BackgroundSizing' and 'BackgroundTransition' properties programmatically in C#, but I haven't found enough info on this to get it working. Does anyone have any ideas?
