wpf绑定材料设计的对话框宽度,要么小于要么超过窗口宽度。

问题描述 投票:3回答:1

我想将对话框的宽度设置为覆盖整个父页面,在这种情况下,UserControland因此是窗口。为此,我尝试将材料设计对话框的宽度绑定到了 ActualWidth 的UserControl。

只要窗口没有最大化,它就能正常工作。

当窗口最大化时,对话框的宽度小于UserControl的宽度。

我试着将UserControl的宽度绑定到用户控件的 ActualWidth 窗口的(Width="{Binding ActualWidth, ElementName=win}"但最糟糕的是,对话框超过了窗口:我缺少什么?

TestWindow.xaml.MyDialog.xaml:

<Window x:Class="Wpf.Views.TestWindow" x:Name="win"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Wpf.Views"
    mc:Ignorable="d"

    Title="TestWindow" Height="450" Width="800">
<Grid>
    <local:MyDialog/> <!-- Width="{Binding ActualWidth, ElementName=win}" -->
    </Grid>
</Window>

MyDialog.xaml

<UserControl x:Class="Wpf.Views.MyDialog" x:Name="self"
         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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
         MinWidth="300"  MinHeight="300" mc:Ignorable="d">
<Grid>
    <materialDesign:DialogHost Identifier="1" BorderBrush="{DynamicResource MaterialDesignDivider}" Height="130" 
    Width="{Binding ActualWidth, ElementName=self}" HorizontalAlignment="Center">
        <Button Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}" Width="130">
            Open
        </Button>
        <materialDesign:DialogHost.DialogContent>
            <StackPanel Orientation="Vertical" Height="130" Width="{Binding ActualWidth, ElementName=self}">
                    <TextBlock Text="Work in Progress" HorizontalAlignment="Center"/>
                    <ProgressBar Style="{DynamicResource MaterialDesignCircularProgressBar}"
      HorizontalAlignment="Center" Margin="16" IsIndeterminate="True" Value="0" />
                    <Button Style="{StaticResource MaterialDesignFlatButton}"
      IsCancel="True" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" HorizontalAlignment="Center">
                        CANCEL
                    </Button>
                </StackPanel>
        </materialDesign:DialogHost.DialogContent>
    </materialDesign:DialogHost>
    </Grid>
</UserControl>

Screen edge

c# wpf xaml wpf-controls material-design-in-xaml
1个回答
3
投票

我猜想,如果将窗口放置在屏幕边缘旁边,除了最大化,你还会看到类似的问题。原因是DialogHost控件中包含了一个 DialogMargin 属性,默认值为所有边上的35。对于你的目的,你可能想把它设置为0。

© www.soinside.com 2019 - 2024. All rights reserved.