【发布时间】:2020-04-23 13:21:09
【问题描述】:
我想设置对话框的宽度以覆盖整个父页面,在这种情况下是 UserControl 和窗口。为此,我尝试将材料设计对话框的宽度绑定到 UserControl 的ActualWidth。
只要窗口未最大化,它就可以正常工作。
当它最大化时,对话框的宽度小于用户控件的宽度:
我尝试将 UserControl 的宽度绑定到窗口的 ActualWidth (Width="{Binding ActualWidth, ElementName=win}"),但最糟糕的是对话框超出了窗口:
我错过了什么?
TestWindow.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>
【问题讨论】:
-
我尝试将自定义用户控件(带有标签的网格)绑定到
Window的ActualWidth属性,它对我来说很好用。 1. 你用的是什么框架版本? 2. 这是DialogHost控件的问题吗?只用一个标签试试,看看你是否得到相同的结果。 -
.Net Framework 4.7.2,我只是尝试使用标签作为
DialogContent,完全相同的行为。 -
如果您完全摆脱材料设计控制而只使用
<Grid><Label/></Grid>会发生什么。这是奇怪的行为。 -
对不起,我没有明白你的意思,问题都是关于材料设计对话框(弹出)的使用。
标签: c# wpf xaml wpf-controls material-design-in-xaml