wpf自定义datagrid控件的一些问题 我写了一个自定义datarid控件,但是数据绑不上去,然后我把这段话注释了之后数据就可以显示了,但是样式就没有了,加上之后数据就绑不上去了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 以下是样式<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication1"> <Style TargetType="{x:Type local:KDataGrids}" BasedOn="{x:Null}"> <Setter Property="RowHeaderWidth" Value="0"></Setter> <Setter Property="AutoGenerateColumns" Value="False"></Setter> <Setter Property="CanUserAddRows" Value="False"></Setter> <Setter Property="CanUserResizeColumns" Value="False"></Setter> <Setter Property="CanUserResizeRows" Value="False"></Setter> <Setter Property="HorizontalGridLinesBrush" Value="LightGray"></Setter> <Setter Property="VerticalGridLinesBrush" Value="LightGray"></Setter> <Setter Property="IsReadOnly" Value="True"></Setter> <Setter Property="BorderThickness" Value="1,0"></Setter> <Setter Property="BorderBrush" Value="LightGray"></Setter> <Setter Property="RowHeight" Value="30"></Setter> <Setter Property="VerticalScrollBarVisibility" Value="Auto"></Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <StackPanel> <DataGridColumnHeader FontFamily="微软雅黑" Background="Red" FontSize="13" Foreground="#0d2d4f" HorizontalAlignment="Center" VerticalAlignment="Top" BorderBrush="Gray" BorderThickness="1,1,1,1" /> <DataGridCell Height="30"> <Grid> <StackPanel> <Border BorderBrush="Gray" BorderThickness="0.5,0.5,0,0.5" > <TextBlock TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="微软雅黑" /> </Border> </StackPanel> </Grid> <DataGridCell.Style> <Style TargetType="DataGridCell"> <Style.Triggers> <Trigger Property="IsSelected" Value="true"> <Setter Property="Control.Background" Value="#FFC7CBCA"/> <Setter Property="Control.BorderThickness" Value="0"></Setter> <Setter Property="Control.Foreground" Value="Red"></Setter> </Trigger> </Style.Triggers> </Style> </DataGridCell.Style> </DataGridCell> <ContentPresenter /> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style></ResourceDictionary> 这是generic里的<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication1"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/WpfApplication1;component/Themes/KDataGrids.xaml" /> </ResourceDictionary.MergedDictionaries></ResourceDictionary>标红的部分就是我引用的样式 打开一个DataGrid, 然后右键创建样式副本,看看DataGrid默认的样式;然后再写自己的样式; 唉,最后一步了! sqlite分页查询 在 c#中, 如何知道視窗是通過滑鼠Focus的、還是在其它視窗有程序 Focus的? 微软编程技术误区 关于工作流持久化 至少一个参数没有被指定值 随机数 男孩子别进!美美接分! LINQ TO SQL 是否支持一个实体对应多个表 网络序列化问题 有没有C#版本的Guava Cache组件 sqlserver内存占用过高
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1">
<Style TargetType="{x:Type local:KDataGrids}" BasedOn="{x:Null}">
<Setter Property="RowHeaderWidth" Value="0"></Setter>
<Setter Property="AutoGenerateColumns" Value="False"></Setter>
<Setter Property="CanUserAddRows" Value="False"></Setter>
<Setter Property="CanUserResizeColumns" Value="False"></Setter>
<Setter Property="CanUserResizeRows" Value="False"></Setter>
<Setter Property="HorizontalGridLinesBrush" Value="LightGray"></Setter>
<Setter Property="VerticalGridLinesBrush" Value="LightGray"></Setter>
<Setter Property="IsReadOnly" Value="True"></Setter>
<Setter Property="BorderThickness" Value="1,0"></Setter>
<Setter Property="BorderBrush" Value="LightGray"></Setter>
<Setter Property="RowHeight" Value="30"></Setter>
<Setter Property="VerticalScrollBarVisibility" Value="Auto"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<StackPanel>
<DataGridColumnHeader FontFamily="微软雅黑" Background="Red" FontSize="13" Foreground="#0d2d4f" HorizontalAlignment="Center" VerticalAlignment="Top" BorderBrush="Gray" BorderThickness="1,1,1,1" />
<DataGridCell Height="30">
<Grid>
<StackPanel>
<Border BorderBrush="Gray" BorderThickness="0.5,0.5,0,0.5" >
<TextBlock TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="微软雅黑" />
</Border>
</StackPanel>
</Grid>
<DataGridCell.Style>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Control.Background" Value="#FFC7CBCA"/>
<Setter Property="Control.BorderThickness" Value="0"></Setter>
<Setter Property="Control.Foreground" Value="Red"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</DataGridCell.Style>
</DataGridCell>
<ContentPresenter />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"> <ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WpfApplication1;component/Themes/KDataGrids.xaml" /> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>标红的部分就是我引用的样式