在 WPF MVVM 应用程序中添加 material 设计后,数据网格不显示滚动条并且设计已过时
Data grid does not show scroll bar and design become obsolete after adding material design in WPF MVVM Application
我在 WPF MVVM 中同时使用 material 设计和 dragablz:TabablzControl application.Material 设计用于设置按钮和文本框的样式。 Grid is located inside tab control.After loading bulk data into data grid 我面临以下设计问题。
- 不显示滚动条。我试过滚动查看器
它没有用。实际上我可以使用箭头键和鼠标向下滚动
滚动。但是滚动条不可见
- 当我们单击数据网格的单行时,该行变得不可见或淡出。
- 当我们点击网格时 header 它会选择所有行
- 虚线显示在window。
任何解决问题的方法。我怎样才能骑 material 仅用于数据网格的设计。
XAML样本
<Grid>
<dragablz:TabablzControl SelectedIndex="0" >
<dragablz:TabablzControl.InterTabController>
<dragablz:InterTabController/>
</dragablz:TabablzControl.InterTabController>
<TabItem Header="File System" >
<Grid ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*">
</ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<GroupBox Grid.Row="0" Grid.Column="0" Header="ISPAC">
<Grid ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*">
</ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="27"></RowDefinition>
</Grid.RowDefinitions>
<DataGrid Name="dataGridCustomer" Height="Auto"
Grid.Row="0" Grid.Column="0"
AutoGenerateColumns="False"
VerticalAlignment="Stretch"
DataContext="{Binding tfs}"
ItemsSource="{Binding
Path=CustomerList,Mode=TwoWay}"
>
<DataGrid.Columns>
<DataGridTextColumn Header="Name"
Binding="
{Binding Path=NameOfFile}"></DataGridTextColumn>
<DataGridTemplateColumn Header="Get ">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="{Binding
Path=Insert}"
Command= "
{Binding RelativeSource={RelativeSource AncestorType={x:Type
DataGrid}}, Path=DataContext.InsertCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource
Mode=Self},Path=DataContext}"></Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Component"
Visibility="Hidden"
Binding="
{Binding Path=Component,Mode=TwoWay}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</GroupBox>
</Grid>
</TabItem>
</dragablz:TabablzControl>
</Grid>
网格UI样本
App.xaml
<Application x:Class="BIExtractionUtilityTool.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:BIExtractionUtilityTool"
xmlns:dragablz="clr-namespace:Dragablz;assembly=Dragablz"
StartupUri="Views/MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- primary color -->
<ResourceDictionary>
<!-- include your primary palette -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
<!--
include three hues from the primary palette (and the associated forecolours).
Do not rename, keep in sequence; light to dark.
-->
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="{StaticResource Primary100}"/>
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="{StaticResource Primary100Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="{StaticResource Primary500}"/>
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="{StaticResource Primary500Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="{StaticResource Primary700}"/>
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="{StaticResource Primary700Foreground}"/>
</ResourceDictionary>
<!-- secondary colour -->
<ResourceDictionary>
<!-- include your secondary pallette -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- include a single secondary accent color (and the associated forecolour) -->
<SolidColorBrush x:Key="SecondaryAccentBrush" Color="{StaticResource Accent200}"/>
<SolidColorBrush x:Key="SecondaryAccentForegroundBrush" Color="{StaticResource Accent200Foreground}"/>
</ResourceDictionary>
<!-- Include the Dragablz Material Design style -->
<ResourceDictionary Source="pack://application:,,,/Dragablz;component/Themes/materialdesign.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- tell Dragablz tab control to use the Material Design theme -->
<Style TargetType="{x:Type dragablz:TabablzControl}" BasedOn="{StaticResource MaterialDesignTabablzControlStyle}" />
</ResourceDictionary>
</Application.Resources>
我认为您看不到某些控件或体验到奇怪的外观(如奇怪的颜色褪色)的原因是控件着色。
Material 设计主题基于或由多种资源组成。这样可以灵活地自定义最终主题。
您基本上拥有可以组合的控件设计主题和颜色主题。
但您始终需要导入适当的资源,设计和颜色主题的组合。
MaterialDesignTheme.Defaults.xaml
包含主要是设计而非颜色相关的基本或共享主题资源,例如控件的默认样式。您已成功合并此资源。
但是您错过了将颜色主题合并到您的 ResourceDictionary
.
例如,您需要导入深色基本主题MaterialDesignTheme.Dark.xaml
:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />
</ResourceDictionary.MergedDictionaries>
或者,您可以使用 BundledTheme
合并颜色主题,它允许通过在单个 BundledTheme
对象中设置相关属性(例如主强调色)来合并相关的配色方案:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<materialDesign:BundledTheme BaseTheme="Dark"
PrimaryColor="Yellow"
SecondaryColor="Red" />
</ResourceDictionary.MergedDictionaries>
我推荐 GitHub 上的 documentation 资源。
我在 WPF MVVM 中同时使用 material 设计和 dragablz:TabablzControl application.Material 设计用于设置按钮和文本框的样式。 Grid is located inside tab control.After loading bulk data into data grid 我面临以下设计问题。
- 不显示滚动条。我试过滚动查看器 它没有用。实际上我可以使用箭头键和鼠标向下滚动 滚动。但是滚动条不可见
- 当我们单击数据网格的单行时,该行变得不可见或淡出。
- 当我们点击网格时 header 它会选择所有行
- 虚线显示在window。
任何解决问题的方法。我怎样才能骑 material 仅用于数据网格的设计。
XAML样本
<Grid>
<dragablz:TabablzControl SelectedIndex="0" >
<dragablz:TabablzControl.InterTabController>
<dragablz:InterTabController/>
</dragablz:TabablzControl.InterTabController>
<TabItem Header="File System" >
<Grid ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*">
</ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<GroupBox Grid.Row="0" Grid.Column="0" Header="ISPAC">
<Grid ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*">
</ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="27"></RowDefinition>
</Grid.RowDefinitions>
<DataGrid Name="dataGridCustomer" Height="Auto"
Grid.Row="0" Grid.Column="0"
AutoGenerateColumns="False"
VerticalAlignment="Stretch"
DataContext="{Binding tfs}"
ItemsSource="{Binding
Path=CustomerList,Mode=TwoWay}"
>
<DataGrid.Columns>
<DataGridTextColumn Header="Name"
Binding="
{Binding Path=NameOfFile}"></DataGridTextColumn>
<DataGridTemplateColumn Header="Get ">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="{Binding
Path=Insert}"
Command= "
{Binding RelativeSource={RelativeSource AncestorType={x:Type
DataGrid}}, Path=DataContext.InsertCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource
Mode=Self},Path=DataContext}"></Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Component"
Visibility="Hidden"
Binding="
{Binding Path=Component,Mode=TwoWay}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</GroupBox>
</Grid>
</TabItem>
</dragablz:TabablzControl>
</Grid>
网格UI样本
App.xaml
<Application x:Class="BIExtractionUtilityTool.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:BIExtractionUtilityTool"
xmlns:dragablz="clr-namespace:Dragablz;assembly=Dragablz"
StartupUri="Views/MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- primary color -->
<ResourceDictionary>
<!-- include your primary palette -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
<!--
include three hues from the primary palette (and the associated forecolours).
Do not rename, keep in sequence; light to dark.
-->
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="{StaticResource Primary100}"/>
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="{StaticResource Primary100Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="{StaticResource Primary500}"/>
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="{StaticResource Primary500Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="{StaticResource Primary700}"/>
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="{StaticResource Primary700Foreground}"/>
</ResourceDictionary>
<!-- secondary colour -->
<ResourceDictionary>
<!-- include your secondary pallette -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- include a single secondary accent color (and the associated forecolour) -->
<SolidColorBrush x:Key="SecondaryAccentBrush" Color="{StaticResource Accent200}"/>
<SolidColorBrush x:Key="SecondaryAccentForegroundBrush" Color="{StaticResource Accent200Foreground}"/>
</ResourceDictionary>
<!-- Include the Dragablz Material Design style -->
<ResourceDictionary Source="pack://application:,,,/Dragablz;component/Themes/materialdesign.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- tell Dragablz tab control to use the Material Design theme -->
<Style TargetType="{x:Type dragablz:TabablzControl}" BasedOn="{StaticResource MaterialDesignTabablzControlStyle}" />
</ResourceDictionary>
</Application.Resources>
我认为您看不到某些控件或体验到奇怪的外观(如奇怪的颜色褪色)的原因是控件着色。
Material 设计主题基于或由多种资源组成。这样可以灵活地自定义最终主题。
您基本上拥有可以组合的控件设计主题和颜色主题。
但您始终需要导入适当的资源,设计和颜色主题的组合。
MaterialDesignTheme.Defaults.xaml
包含主要是设计而非颜色相关的基本或共享主题资源,例如控件的默认样式。您已成功合并此资源。
但是您错过了将颜色主题合并到您的 ResourceDictionary
.
例如,您需要导入深色基本主题MaterialDesignTheme.Dark.xaml
:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />
</ResourceDictionary.MergedDictionaries>
或者,您可以使用 BundledTheme
合并颜色主题,它允许通过在单个 BundledTheme
对象中设置相关属性(例如主强调色)来合并相关的配色方案:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<materialDesign:BundledTheme BaseTheme="Dark"
PrimaryColor="Yellow"
SecondaryColor="Red" />
</ResourceDictionary.MergedDictionaries>
我推荐 GitHub 上的 documentation 资源。