我用棱镜框架在wpf中创建了一个Costum对话框请求。一切工作正常,除了弹出对话框未位于主窗口(关联窗口)上方居中。我遵循了Prism examples from GitHub网站上的棱镜示例 28-CustomRequest 。
我用CenterOverAssociatedObject="True"
和WindowStartupLocation="CenterScreen"
进行了尝试,但没有任何效果。
另一个奇怪的是,当我执行应用程序并引发自定义对话框时,
检查live-properties-explorer中的wpf对话框属性,它在 Lokal> Top 下显示Top = -19
??
这是我的MainWindow:
<controls:MetroWindow x:Class="Views.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:regions="http://www.codeplex.com/prism"
xmlns:prism="http://prismlibrary.com/"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:views="clr-namespace:MainApp.Views"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
BorderBrush="{DynamicResource AccentBaseColorBrush}"
ResizeMode="CanResizeWithGrip" SizeToContent="WidthAndHeight"
MinWidth="1280" MinHeight="768"
WindowStartupLocation="CenterScreen"
Height="Auto" Width="Auto">
<i:Interaction.Triggers>
<prism:InteractionRequestTrigger SourceObject="{Binding CustomDialogRequest}">
<prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True" > '<---My tries
<prism:PopupWindowAction.WindowStyle>
<Style TargetType="Window">
<Setter Property="Icon" Value="/MainApp;component/Images/img.ico"/>
<Setter Property="Height" Value="400"/>
<Setter Property="Width" Value="400"/>
</Style>
</prism:PopupWindowAction.WindowStyle>
<prism:PopupWindowAction.WindowContent>
<views:MyCustomView />
</prism:PopupWindowAction.WindowContent>
</prism:PopupWindowAction>
</prism:InteractionRequestTrigger>
</i:Interaction.Triggers>
<Grid>
'Button which triggers the custom pop up
</Grid>
</controls:MetroWindow>
MyCustomView
:
<UserControl x:Class="Views.MyCustomView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MainApp"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
<Grid>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBox Text="Text"/>
</StackPanel>
</Grid>
</UserControl>
此Sub触发自定义对话框:
Public ReadOnly Property RaiseCustomDialog As DelegateCommand = New DelegateCommand(AddressOf Me.CustomDialog)
Private Sub CustomDialog()
Dim testdialog As New CustomDialog.CustomDialog() With {.Title = UIResources.Commission & ":"}
CustomDialogRequest.Raise(testdialog,
Sub(response)
ID = DirectCast(response, CustomDialog.CustomDialog).SelectedItem
If DirectCast(response, CustomDialog.CustomDialog).Confirmed AndAlso Not String.IsNullOrEmpty(ID) Then
StuffToDo(ID)
Else
Msgbox("Test")
End If
End Sub
)
End Sub