我正在嘗試使用 MaterialDesigns 打開一個DialogHost包含Border紅色背景和圓角的彈出視窗。

我只想要紅色,而不是灰色背景。它從何而來?如何洗掉它?
<materialDesign:DialogHost Panel.ZIndex="566" x:Name="mainWindowDialogHost">
<materialDesign:DialogHost.DialogContent>
<Border Height="500" Width="200"
CornerRadius="120" Background="Red">
</Border>
</materialDesign:DialogHost.DialogContent>
</materialDesign:DialogHost>
uj5u.com熱心網友回復:
當您有來自 DialogHost 的對話框時,有 2 個背景
第一個是 DialogHost 區域本身,可以通過設定 OverlayBackground="Transparent" 將其設定為透明。
第二個如果是在對話主機的模板中設定的內容之一,并且沒有公開。因此,要么重寫對話宿主的完整模板(相當多的 XAML),要么使用背后的代碼找到對話內容的控制元件并更改其背景。
讓它像你想要的一樣的例子,用材料設計 4.0.0 測驗(我修改了最后一個功能以使其在這種情況下作業,可能可以使它更干凈)
XAML
<materialDesign:DialogHost OverlayBackground="Transparent" Loaded="DialogHost_Loaded" IsOpen="{Binding IsChecked, ElementName=showdialog}" CloseOnClickAway="True" >
<materialDesign:DialogHost.DialogContent>
<Border CornerRadius="50" Background="Red" Height="200" Width=" 200" ></Border>
</materialDesign:DialogHost.DialogContent>
...
</materialDesign:DialogHost>
背后的代碼
private void DialogHost_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
Card card = FindVisualChild<Card>((DialogHost)sender);
if (card != null)
{
card.Background = Brushes.Transparent;
}
}
private static T FindVisualChild<T>(Visual visual) where T : Visual
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(visual); i )
{
Visual child = (Visual)VisualTreeHelper.GetChild(visual, i);
if (child != null)
{
T correctlyTyped = child as T;
if (correctlyTyped != null)
return correctlyTyped;
if (child as Popup != null) // specific to this case
{
Popup popup = (Popup)child;
if (popup.Child != null)
{
T subChild = popup.Child as T;
if (subChild != null)
return subChild;
}
}
T descendent = FindVisualChild<T>(child);
if (descendent != null)
return descendent;
}
}
return null;
}
uj5u.com熱心網友回復:
您可以使用這樣的DialogBackground屬性指定對話主持人的背景。
<materialDesign:DialogHost Panel.ZIndex="566" x:Name="mainWindowDialogHost" DialogBackground="Red">
此屬性自 4.3.0 版起可用。對于舊版本,您必須調整默認樣式。
不幸的是, 的角半徑DialogHost是硬編碼的。為了更改它,您必須復制默認樣式(控制元件模板)并對其進行調整。將其從
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/381193.html
標籤:C# 小白 xaml wpf-控件 材料设计在 xaml
上一篇:在wpf中,我如何從其他ViewModel參考MainWindowViewModel?
下一篇:影像分割之Swin-Unet分享
