2
我目前在WPF中使用MVVM,我在我的项目中安装了MahappsMetro。我想要更改默认的DataGrid样式,而不会丢失MetroDataGrid样式的所有属性(Style for MahappsMetro中的DataGrid)。WPF - 修改MahappsMetro DataGrid风格
我只是想改变一些触发器为IsMouseOver和IsSelected,我试着这样做:
我的App.xaml
<Style x:Key="TransparentDataGrid" TargetType="{x:Type DataGrid}" BasedOn="{StaticResource MetroDataGrid}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGrid}">
<DataGrid>
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Transparent" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Foreground" Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
</DataGrid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
定义了这个风格,我结合这个风格,我需要它
Style="{DynamicResource TransparentDataGrid}"
但我得到异常:
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
我也试过:
我创建了MainViewModel.xaml的风格,但我不知道怎么这种风格绑定到其他意见。
{StaticData {}:}}是不可能的,因为在App.xaml中,WPF中不支持MetroDataGrid。 – CampDev
您需要为''标签中的相同名称空间定义名称空间。例如'xmlns:mapp =“clr-namespace:MahApps.Metro.Controls”'并将其改为'{StaticResource {x:Type mapp:MetroDataGrid}} –
pushpraj
我在尝试,但'{StaticResource {x:Type mapp: Metro DataGrid}}'这是不可能的。 绑定将是'{StaticResource {x:Type mapp:TypeName = DataGrid}}(因为在mapp之后:必须是Type或TypeName)。但是,对于最后的语法,存在一个问题,“x:type参数无效”。 – CampDev