0

ボタンを持つベースWPF ページ (ウィンドウではない)があります。ボタンをクリックすると、モーダル ダイアログを開いて親 (WPF ページ) の右下に配置する必要があります。

次のようにモーダルダイアログを作成しました::

  CDialog dialog = new CDialog();
  dialog.ShowDialog();

親 WPF ページの右下部分にダイアログを配置する方法がわかりません。!!

編集 1: CDialog のコードビハインドでこれら 2 つのメソッドを試していますが、Parent を null として取得しています!!

   private void Window_Loaded(object sender, RoutedEventArgs e)
    {

         object obj = (sender as Window).Parent; //nullreference exception
    }

    private void Window_LayoutUpdated(object sender, EventArgs e)
    {
        object obj = (sender as Window).Parent; //nullreference exception
    }

どの方法を使用すればよいですか??

4

2 に答える 2

0

おそらく、を使用して、カスタムモーダルダイアログソリューションを試す必要がありますDispatcherFrame

これは私が非常によく似た解決策(リンクテキスト)のために思いついた例です-例を実行して、私が何を意味するかを見てください:

public partial class Window1 : Window
{
    private DispatcherFrame frame;
    private readonly ObservableCollection<string> collection = new ObservableCollection<string>();
    public Window1()
    {
        InitializeComponent();
        DataContext = collection;
    }

    private void GetData(object sender, RoutedEventArgs e)
    {
        collection.Clear();
        frame = new DispatcherFrame();
        popupGrid.Visibility = Visibility.Visible;
        System.Windows.Threading.Dispatcher.PushFrame(frame); // blocks gui message pump & creates nested pump
        var count = int.Parse(countText.Text); // after DispatcherFrame is cancelled, it continues
        for (int i = 0; i < count; i++)
            collection.Add("Test Data " + i);
        popupGrid.Visibility = Visibility.Hidden;
    }

    private void DataCountEntered(object sender, RoutedEventArgs e)
    {
        frame.Continue = false; // un-blocks gui message pump
    }
}

これはXAMLです

<Grid>
<TabControl>
  <TabItem Header="TabItem">
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>
      <ListBox ItemsSource="{Binding}"/>
      <Button HorizontalAlignment="Left" VerticalAlignment="Top" Width="75"
              Content="Get Data" Grid.Row="1" Margin="0,5" Click="GetData"/>
    </Grid>
  </TabItem>
  <TabItem Header="TabItem">
    <Grid/>
  </TabItem>
</TabControl>
<Grid Name="popupGrid" Visibility="Hidden">
  <Grid.Background>
    <SolidColorBrush Opacity="0.4" Color="#FFD8CFCF"/>
  </Grid.Background>
  <Border HorizontalAlignment="Center" VerticalAlignment="Center" Width="200" Height="100"
          BorderBrush="Black" BorderThickness="1" Background="White" Padding="5">
    <StackPanel>
      <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Enter Number Of Items"/>
      <TextBox HorizontalAlignment="Left" Text="10" TextWrapping="Wrap" Margin="0,3"
               Width="100" Name="countText"/>
      <Button HorizontalAlignment="Left" Width="75" Content="Do Data Add" Click="DataCountEntered"/>
    </StackPanel>
  </Border>
</Grid>

于 2010-11-24T11:27:22.083 に答える
0

次のコードはトリックを行う必要があります。

child.Left = parent.ActualWidth - child.ActualWidth;
child.Top = parent.ActualHeight - child.ActualHeight;

注:このコードは、子がレンダリングされていることを前提としているため、Actual* プロパティは正しい値を持っています。したがって、子がレンダリング/表示されていることがわかっている場所にこのコードを配置してください。

于 2010-11-24T11:18:41.943 に答える