本文介绍了创建Datagrid用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Hai 我创建了一个名为IGrid的用户控件,我改回颜色,AutoGenerateColumns =False等并编译成dll。 但是当我将这个控件添加到wpf表单时,我没有得到新控件的设置。我得到默认颜色并且AutoGenerateColumns变为true 我使用此代码 Xaml < DataGrid x:Class = IGrid 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 xmlns:local = clr-namespace:MyGrid mc:Ignorable = d 高度 = 200 宽度 = 400 AutoGenerateColumns = False > < DataGrid .Background > < LinearGradientBrush EndPoint = 0.5,1 StartPoint = 0.5,0 > < GradientStop 颜色 = #FF787575 偏移量 = 1 / > < GradientStop 颜色 = 白色 / > < / LinearGradientBrush > < / DataGrid.Background > < / DataGrid > 请帮我一下是问题。 谢谢。解决方案 您好,尝试设置背景和 AutoGenerateColumns 代码背后,例如, public partial class IGrid:DataGrid { public IGrid() { InitializeComponent(); this .AutoGenerateColumns = true ; this .Background = new SolidColorBrush(Colors.LightBlue); } } 创建UserControl库并在那里定义自定义用户控件。 hai 感谢您的回复。 我也尝试了这个但是没有工作。 我创建了新的UserControl库,在代码中写了AutoGenerateColumns =False,编译成dll文件。在新项目中,我在ToolBox中添加了这个,当我在wpf表单上拖动此控件时,我得到AutoGenerateColumns =True,颜色为默认值等。我必须再次更改所有属性。请给出解决方案 谢谢 Hai I created a user control called IGrid ,I changed back color , AutoGenerateColumns="False" etc. and compiled to dll. But when i add this control to a wpf form I am not getting the seting in new control.I get default color and AutoGenerateColumns becomes to true I use this codeXaml <DataGrid x:Class="IGrid" 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" xmlns:local="clr-namespace:MyGrid" mc:Ignorable="d" Height="200" Width="400" AutoGenerateColumns="False"> <DataGrid.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF787575" Offset="1"/> <GradientStop Color="White"/> </LinearGradientBrush> </DataGrid.Background></DataGrid> Please help me what is the problem.thanks. 解决方案 Hi, Try to set Background and AutoGenerateColumns in code behind, like,public partial class IGrid : DataGrid{ public IGrid() { InitializeComponent(); this.AutoGenerateColumns = true; this.Background = new SolidColorBrush(Colors.LightBlue); }}Create UserControl Library and define your custom user controls there.haiThanks for reply. I tried this also but not working.I created new UserControl Library wrote AutoGenerateColumns="False" in code,compiled to dll file. In new project i added this in ToolBox , when i drag this control on a wpf form I get AutoGenerateColumns="True" , color to default etc. I have to change again all properties. Please give a solutionthanks 这篇关于创建Datagrid用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-18 02:36