Je travaille sur une boîte de dialogue modale (je ne suis pas sûr du terme UX exact) qui est affichée en ligne, à l'intérieur d'un contrôle ou d'une fenêtre avec un arrière-plan assombri .Boîte de dialogue contextuelle simple dans WPF (incrustation dans la fenêtre)
exemple visuel
Ce que j'ai essayé est de mettre un <ContentPresenter />
à l'intérieur du XAML de la fenêtre et puis juste instancier comme ceci:
<local:Popup Grid.RowSpan="2">
<TextBlock Text="Popup test..." />
</local:Popup>
Cependant, le XAML remplace l'intégralité du XAML au lieu d'être placé à l'emplacement du ContentPresenter.
Q: Comment le ContentPresenter est-il utilisé correctement?
Popup.xaml
<ContentControl
x:Class="[...].Popup"
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:[...]"
mc:Ignorable="d" d:DesignWidth="300" d:DesignHeight="300">
<Grid Background="#7f000000">
<Grid Background="White" HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel Margin="20">
<TextBlock Text="{Binding Title, RelativeSource={RelativeSource AncestorType=UserControl}}" FontSize="20" />
<ContentPresenter />
</StackPanel>
</Grid>
</Grid>
</ContentControl>
Popup.xaml.cs
using System.Windows;
namespace [...]
{
public partial class Popup : ContentControlBase
{
public static DependencyProperty TitleProperty = DependencyProperty.Register(nameof(Title), typeof(string), typeof(Popup));
public string Title
{
get
{
return (string)GetValue(TitleProperty);
}
set
{
SetValue(TitleProperty, value);
}
}
public Popup()
{
InitializeComponent();
}
}
}
Le fait '' toute l'affaire. Je vous remercie! +1 –
bytecode77