0

I am working on a WPF Project with Caliburn Micro. Please consider the following code snippets:

PopupWindowView.xaml

<Window x:Class="PTSRDesktopUI.Views.PopupWindowView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:PTSRDesktopUI.Views"
        mc:Ignorable="d" ShowInTaskbar="True"
        ResizeMode="NoResize" SizeToContent="Height" FontSize="24"
        MouseDown="Window_MouseDown" Background="#FFF7F7F7" Icon="/Images/infoicon_8Ve_icon.ico"
        Title="Pfad Info" Height="300" Width="500">

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <TextBlock FontSize="20" Grid.Column="1" Text="{Binding Path=Path}" Margin="10 10 10 10"
                 HorizontalAlignment="Center" VerticalAlignment="Center" IsEnabled="False" 
                    FontFamily="Segoe UI Light"/>
    </Grid>
</Window>

PopupWindowViewModel.cs

using Caliburn.Micro;
using PTSRDesktopUI.Models;

namespace PTSRDesktopUI.ViewModels
{
    public class PopupWindowViewModel : Screen
    {
        private string _path;

        public PopupWindowViewModel(ChangesModel model)
        {
            _path = model.ParameterPfad;
        }

        public string Path
        {
            get { return _path; }
            set
            {
                _path = value;
                NotifyOfPropertyChange(() => Path);
            }
        }
    }
}

OverviewView.xaml

    <DataGridTemplateColumn CellStyle="{StaticResource DataGridCellCentered}" Header="Info">
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <Button BorderThickness="0" Height="30" Width="30" 
                        Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
                        cal:Message.Attach="ShowPath($this)">
                    <Image Source="/Images/infoicon.png"/>
                </Button>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>

OverviewViewModel.cs

private readonly IWindowManager manager = new WindowManager();

public void ShowPath(ChangesModel model)
{
    manager.ShowWindow(new PopupWindowViewModel(model), null, null);           
}

All this does is, when the Button in the DataGrid is pressed, the PopupWindow pops up and displays some data. It all works fine. The only thing I cannot seem to figure out is how to display the new PopupWindow at the same location where the clicked Button is, or rather where my mouse pointer is. I have read all the other StackOverflow questions regarding this problem but none of them does the trick for me. I either get an error or it just does not work. Anyone has any ideas how to solve this?

Mysterio
  • 139
  • 12
  • There is a reason for not using the popup control and instead using your window? – Stefano Cavion Feb 12 '20 at 09:40
  • @StefanoCavion I started out with popup control, but it was difficult to diplay the data via Caliburn Micro. I found that using a new window was much easier. – Mysterio Feb 12 '20 at 09:45
  • than you should check [this](https://stackoverflow.com/questions/1545258/changing-the-start-up-location-of-a-wpf-window) – Stefano Cavion Feb 12 '20 at 09:48

0 Answers0