gpt4 book ai didi

c# - 在WPF MVVM应用程序中添加 Material 设计后,数据网格不显示滚动条,并且设计变得过时

转载 作者:行者123 更新时间:2023-12-03 10:15:33 27 4
gpt4 key购买 nike

我在WPF MVVM应用程序中同时使用了 Material 设计和dragablz:TabablzControl。 Material 设计用于设置按钮和文本框的样式。网格位于选项卡控件内部。将批量数据加载到数据网格中后,我面临以下设计问题。

  • 它不显示滚动条。我曾经尝试过使用滚动查看器
    它没有用。其实我可以使用箭头键和鼠标向下滚动
    滚动。但是滚动条不可见。
  • 当我们单击数据网格的单行时,该行变得不可见或褪色。
  • 当我们单击网格标题时,它将选择所有行
  • 窗口中显示一条虚线。

  • 任何解决问题的方法。我如何才能只针对数据网格进行 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示例
    enter image description here
    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资源。

    关于c# - 在WPF MVVM应用程序中添加 Material 设计后,数据网格不显示滚动条,并且设计变得过时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62555439/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com