导航到带有堆栈面板内按钮的页面的框架
a frame that navigates to a page with a button inside a stackpanel
我在 WPF 表单按钮中有一个按钮(使用 MaterialDesign 主题)样式不正确,我哪里出错了?。 DataGrid 中的按钮很好。我在 mainWindow 上尝试在 Window 附近做 Foreground="white" 但是当我把主题从所有 returns 改为正常 WPF form with the text colour (lower right) missing
app.xamp:
<Application x:Class="App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:P2Assessment"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
StartupUri="mainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Purple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
主要 window 与框架:
<Window x:Name="frmMain" x:Class="mainWindow"
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Foreground="White"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"
xmlns:local="clr-namespace:P2Assessment"
mc:Ignorable="d"
Title="XYZ & Co." Height="460" Width="800">
<Grid>
<materialDesign:Card Margin="16">
<Frame x:Name="frame" Margin="10,15,10,5">
<!-- navigate to different views-->
</Frame>
</materialDesign:Card>
</Grid>
框架导航页面:
<Page x:Class="P2Assessment.ViewOrders"
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"
Foreground="Wheat"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="ViewOrders">
<Grid>
<StackPanel>
<Label Content="View orders" FontSize="28" FontWeight="Bold" HorizontalAlignment="Center"/>
<DataGrid x:Name="dgOrders" AutoGenerateColumns="False" Height="260">
<DataGrid.Columns>
<DataGridTextColumn Header="Id" Binding="{Binding Id}" Width="15"/>
<DataGridTextColumn Header="Date / Time" Binding="{Binding dateTime}" Width="200"/>
<DataGridTextColumn Header="# Items" Binding="{Binding Items}" Width="200"/>
<DataGridTextColumn Header="Total" Binding="{Binding Total}" Width="75"/>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="View order details" Click="ViewOrderDetails"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,15,0,0" >
<Button Content="Add an order" Margin="0,0,15,0" Padding="15" Click="AddOrderClicked" Style="{StaticResource MaterialDesignRaisedAccentButton}" Width="100"/>
<Button Content="Close" Margin="0,0,15,0" Padding="15" Click="Button_Click"/>
</StackPanel>
</StackPanel>
</Grid>
感谢您的帮助
这是因为 Padding="15"
一定是把内容推到按钮区域之外了
我在 WPF 表单按钮中有一个按钮(使用 MaterialDesign 主题)样式不正确,我哪里出错了?。 DataGrid 中的按钮很好。我在 mainWindow 上尝试在 Window 附近做 Foreground="white" 但是当我把主题从所有 returns 改为正常 WPF form with the text colour (lower right) missing
app.xamp:
<Application x:Class="App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:P2Assessment"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
StartupUri="mainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Purple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
主要 window 与框架:
<Window x:Name="frmMain" x:Class="mainWindow"
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Foreground="White"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"
xmlns:local="clr-namespace:P2Assessment"
mc:Ignorable="d"
Title="XYZ & Co." Height="460" Width="800">
<Grid>
<materialDesign:Card Margin="16">
<Frame x:Name="frame" Margin="10,15,10,5">
<!-- navigate to different views-->
</Frame>
</materialDesign:Card>
</Grid>
框架导航页面:
<Page x:Class="P2Assessment.ViewOrders"
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"
Foreground="Wheat"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="ViewOrders">
<Grid>
<StackPanel>
<Label Content="View orders" FontSize="28" FontWeight="Bold" HorizontalAlignment="Center"/>
<DataGrid x:Name="dgOrders" AutoGenerateColumns="False" Height="260">
<DataGrid.Columns>
<DataGridTextColumn Header="Id" Binding="{Binding Id}" Width="15"/>
<DataGridTextColumn Header="Date / Time" Binding="{Binding dateTime}" Width="200"/>
<DataGridTextColumn Header="# Items" Binding="{Binding Items}" Width="200"/>
<DataGridTextColumn Header="Total" Binding="{Binding Total}" Width="75"/>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="View order details" Click="ViewOrderDetails"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,15,0,0" >
<Button Content="Add an order" Margin="0,0,15,0" Padding="15" Click="AddOrderClicked" Style="{StaticResource MaterialDesignRaisedAccentButton}" Width="100"/>
<Button Content="Close" Margin="0,0,15,0" Padding="15" Click="Button_Click"/>
</StackPanel>
</StackPanel>
</Grid>
感谢您的帮助
这是因为 Padding="15"
一定是把内容推到按钮区域之外了