私はwpfでカスタムメッセージボックスを作成しました。メインウィンドウ内の子ウィンドウの位置を設定する(親)
カスタムメッセージボックスビューXAML:私のメインウィンドウ(親)ユーザーがボタンをクリックしたときに、私はボタンから呼び出しの例として、メッセージボックスウィンドウWPFこのカスタムを示してから、
<Window x:Class="My.XAML.Controls.Windows.WpfMessageBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WpfMessageBox" MinHeight="160"
MinWidth="420" MaxHeight="750" MaxWidth="750"
Background="Transparent"
SizeToContent="WidthAndHeight"
WindowStartupLocation="Manual"
ShowInTaskbar="False" ResizeMode="NoResize"
WindowStyle="None" Topmost="True">
</Window>
ときにそれを*
var messageBoxResult = WpfMessageBox.Show("Title", "MyMessage",
MessageBoxButton.YesNo, WpfMessageBox.MessageBoxImage.Warning, this, EnumLocation.TopLeft);
カスタムメッセージボックスのコードビハインドxaml.cs:クリックされた
public partial class WpfMessageBox : Window
{
private WpfMessageBox()
{
InitializeComponent();
}
public static MessageBoxResult Show(string caption, string text, MessageBoxButton button, MessageBoxImage image, Window parent, EnumLocation location)
{
switch (location)
{
case MessageBoxLocation.TopLeft:
this.Top = parent.Top; // works
this.Left = parent.Left; // works
break;
case MessageBoxLocation.TopCenter:
this.Top = parent.Top;
this.Left = ? // what goes here?
break;
case MessageBoxLocation.TopRight:
this.Top = parent.Top;
this.Left = (parent.Left + parent.Width) - this.Width; // not working, what goes here?
break;
case MessageBoxLocation.MiddleLeft:
this.Left = parent.Left;
this.Top = ? // what goes here?
break;
case MessageBoxLocation.MiddleCenter:
this.WindowStartupLocation = WindowStartupLocation.CenterScreen; // not working so what goes here?
break;
case MessageBoxLocation.MiddleRight:
this.Top = ? // what goes here?
this.Left = ? // what goes here?
break;
case MessageBoxLocation.BottomLeft:
this.Top = (parent.Top + parent.Height) - this.Height; // Not working this
this.Left = parent.Left;
break;
case MessageBoxLocation.BottomCenter:
this.Top = (parent.Top + parent.Height) - this.Height; // not working
this.Left = ? // what goes here?
break;
case MessageBoxLocation.BottomRight:
this.Top = (parent.Top + parent.Height) - this.Height; // not working
this.Left = (parent.Left + parent.Width) - this.Width; // not working
break;
default:
break;
}
}
}
場合によっては設定することができない場合もあれば、設定したものもありますが動作しません。 誰かが正しく設定するのに手伝ってもらえますか?
をお試しください:https://stackoverflow.com/questions/2446602/wpf-set-dialog-windowメインウィンドウとの相対的な位置づけ私は一見を持ってフィードバックを返します。 – user1624552
もちろん静的メソッドでthis.Widthにアクセスすることはできません。あなたのウィンドウで行うべきShowメソッドは何ですか? – mm8