安装的应用程序中的结果与调试期间的结果不同

时间:2014-10-09 07:40:59

标签: c# wpf button datagrid

我有一个程序,我在其中以编程方式添加按钮列。当我在视觉工作室时,它会相应地工作,但是当我安装它时,该应用程序崩溃了。当我删除按钮的背景图像时,它甚至可以在已安装的应用程序中工作。这是我在数据网格中添加带按钮的列的代码。

   ///Here is the part where I declare the path of my image background

  Image EditImage = new Image();
  EditImage.Source = new BitmapImage(new Uri("../../Icons/pencil.png", UriKind.Relative));
  ImageBrush imgEditBrush = new ImageBrush(EditImage.Source);


 //Here is the part where I add my column

   DataGridTemplateColumn Edit = new DataGridTemplateColumn();
   Edit.Header = "Edit";
   FrameworkElementFactory EditFactory = new FrameworkElementFactory(typeof(Button));
   Binding b1 = new Binding("IsClicked");
   b1.Mode = BindingMode.TwoWay;
   EditFactory.SetValue(Button.BackgroundProperty, imgEditBrush);
   EditFactory.SetValue(Button.WidthProperty, size);
   EditFactory.AddHandler(Button.ClickEvent, new RoutedEventHandler(EditTransaction_Click));
   DataTemplate CellEdit = new DataTemplate();
   CellEdit.VisualTree = EditFactory;
   Edit.CellTemplate = CellEdit;
   dgDataGrid.Columns.Add(Edit);

我对Button.BackgroundProperty的声明有什么问题?谁能帮我吗。提前谢谢。

0 个答案:

没有答案
相关问题