Hi ,
I have a WPF app and I am using the library Modern UI too. I am trying to situate on a Page my user control in a relative position of the grid/screen. My final objective is to position my user controls (over a shape or background image) in x/y positions defined by me.
I have been reading about this topic and they recomend to use:
Point locationFromWindow = myusercontrol.TranslatePoint(new Point(0, 0),this );
Point locationFromScreen = myusercontrol.PointToScreen(locationFromWindow);
It looks simple but is giving me next error:
For now I am testing it with a simple button in my page:
<Grid Style="{StaticResource ContentRoot}">
<Grid ShowGridLines="True" x:Name="mainGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Content="Button" x:Name="b1" />
</Grid>
</Grid>
In the code behind of the page "Home" I added:
public partial class Home : UserControl
{
public Home()
{
InitializeComponent();
Point locationFromWindow = b1.TranslatePoint(new Point(0, 0),this );
Point locationFromScreen = b1.PointToScreen(locationFromWindow);
}
}
It returns a parsing error: '
Additional information: 'The invocation of the constructor on type Test.Pages.Home' that matches the specified binding constraints threw an exception.' Line number '8' and line position '6'.
I tried adding the button from the code behind too ( and not from the XAML) with the commented lines , but it also didn't works.
Why is this happening? Any suggestion for a better performance of my objective?