Custom Popup Size Using Interaction Request

I used the user confirmation popup, this is XAML:

<Grid>
    <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <TextBlock Text="{Binding Content}" TextWrapping="Wrap" Width="150"/>
    <StackPanel Orientation="Horizontal" Margin="6" Grid.Row="1">
            <Button x:Name="YesBtn" Width="100" Content="OK" Click="OnOk_Click"/>
            <Button x:Name="NoBtn" Width="100" Content="No" Click="OnNo_Click"/>
    </StackPanel>
</Grid>

and this is the code:

public partial class CustomConfirmation : IInteractionRequestAware
{
    public CustomConfirmation()
    {
        InitializeComponent();
    }
    public IConfirmation Confirmation
    {
        get { return this.DataContext as IConfirmation; }
        set { this.DataContext = value; }
    }

    public string Title { get; set; }
    public bool Confirmed { get; set; }
    public INotification Notification { get; set; }
    public Action FinishInteraction { get; set; }
    private void OnOk_Click(object sender, RoutedEventArgs e)
    {
        if (FinishInteraction != null)
        {
            Confirmation.Confirmed= true;
            FinishInteraction();
        }
    }

    private void OnNo_Click(object sender, RoutedEventArgs e)
    {
        if (FinishInteraction != null)
        {
            Confirmation.Confirmed = false;
            FinishInteraction();
        }
    }
}

In the model class view, I am:

  • two commands (DispalyLongTextCommand and DispalyShortTextCommand): one to display a long message, and the other to display a short message
  • and I have an InteractionRequest ConfirmationRequest object initialized in ctor to spoof links.

If I show a long message, my own window will change its contents to a hole message, this is normal! but if you want to display a short message, my window remains the same size!

note: even I set the SizeToContent style to WidthAndHeight, but it does not work.

<ei:Interaction.Triggers>
        <prism:InteractionRequestTrigger SourceObject="{Binding ConfirmationRequest, Mode=TwoWay}">
            <prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True">
                <prism:PopupWindowAction.WindowStyle>
                    <Style TargetType="Window">
                        <Setter Property="SizeToContent" Value="WidthAndHeight"/>
                    </Style>
                </prism:PopupWindowAction.WindowStyle>
                <prism:PopupWindowAction.WindowContent>
                    <local:CustomConfirmation/>
                </prism:PopupWindowAction.WindowContent>
            </prism:PopupWindowAction>
        </prism:InteractionRequestTrigger>
    </ei:Interaction.Triggers>

window size depends on content

Window save previous size

Can you guide me, thanks in advance

: , :

public CustomConfirmationView()
    {
        InitializeComponent();
        Loaded += CustomPopupView_Loaded;
    }

    private void CustomPopupView_Loaded(object sender, RoutedEventArgs e)
    {
        var parentWindow = this.Parent as Window;
        if (parentWindow != null)
        {
            parentWindow.Measure(parentWindow.DesiredSize);
        }
    }
+4
2

WindowContent , . , , , CustomPopupView . , , , CustomPopupView.Height , , CustomPopupView. , , :

    public CustomPopupView()
    {
        InitializeComponent();
        Loaded += CustomPopupView_Loaded;
    }

    private void CustomPopupView_Loaded(object sender, RoutedEventArgs e)
    {
        var parentWindow = this.Parent as Window;
        if (parentWindow != null)
            parentWindow.MinHeight = _txt.ActualHeight + 75;
    }

. '_txt' - TextBlock Content.

+2

, , Prism. MinWidth MinHeight XAML 300 150 . , / , . , , .

Prism , . , , .

\ Source\Wpf\Prism.Wpf\\DefaultPopupWindows\DefaultConfirmationWindow.xaml

, Prism , , , , . GitHub. https://github.com/PrismLibrary/Prism/issues

0

Source: https://habr.com/ru/post/1616550/


All Articles