本文整理汇总了C#中System.Windows.FrameworkElementFactory.SetResourceReference方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElementFactory.SetResourceReference方法的具体用法?C# FrameworkElementFactory.SetResourceReference怎么用?C# FrameworkElementFactory.SetResourceReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.FrameworkElementFactory
的用法示例。
在下文中一共展示了FrameworkElementFactory.SetResourceReference方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UcTableView_SizeChanged
void UcTableView_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (dt == null)
{
return;
}
_gridview.Columns.Clear();
foreach (DataColumn c in dt.Columns)
{
GridViewColumn gvc = new GridViewColumn();
gvc.Header = c.ColumnName;
if (BShowDetails)
{
gvc.Width = (_listview.ActualWidth - 65) / dt.Columns.Count;
}
else
{
gvc.Width = (_listview.ActualWidth - 25) / dt.Columns.Count;
}
gvc.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);
//gvc.DisplayMemberBinding = (new Binding(c.ColumnName));
FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
text.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
DataTemplate dataTemplate = new DataTemplate() { VisualTree = text };
gvc.CellTemplate = dataTemplate;
_gridview.Columns.Add(gvc);
}
if (BShowDetails)
{
GridViewColumn gvc_details = new GridViewColumn();
gvc_details.Header = "详情";
FrameworkElementFactory button_details = new FrameworkElementFactory(typeof(Button));
button_details.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
button_details.SetValue(Button.WidthProperty, 40.0);
button_details.AddHandler(Button.ClickEvent, new RoutedEventHandler(details_Click));
button_details.SetBinding(Button.TagProperty, new Binding(dt.Columns[1].ColumnName));
button_details.SetValue(Button.ContentProperty, ">>");
button_details.SetValue(Button.ForegroundProperty, Brushes.Blue);
button_details.SetValue(Button.FontSizeProperty, 14.0);
button_details.SetBinding(Button.VisibilityProperty, new Binding(dt.Columns[0].ColumnName) { Converter = new VisibleBtnConverter() });
DataTemplate dataTemplate_details = new DataTemplate() { VisualTree = button_details };
gvc_details.CellTemplate = dataTemplate_details;
_gridview.Columns.Add(gvc_details);
}
_listview.ItemsSource = null;
_listview.ItemsSource = dt.DefaultView;
}
示例2: update
private void update()
{
if (table == null )
{
return;
}
int sumWidth = 0;
for (int j = 0; j < table.Columns.Count; j++)
{
int maxWidth = System.Text.Encoding.Default.GetByteCount(table.Columns[j].ColumnName.ToString());
for (int i = 0; i < table.Rows.Count; i++)
{
if (maxWidth < System.Text.Encoding.Default.GetByteCount(table.Rows[i][j].ToString().Trim()))
{
maxWidth = System.Text.Encoding.Default.GetByteCount(table.Rows[i][j].ToString().Trim());
}
}
sumWidth += maxWidth;
myColumns[table.Columns[j].ColumnName.ToLower()].Width = maxWidth;
}
_gridview.Columns.Clear();
for (int i = 0; i < table.Columns.Count; i++)
{
DataColumn c = table.Columns[i];
if (!myColumns[c.ColumnName.ToLower()].BShow)
{
continue;
}
GridViewColumn gvc = new GridViewColumn();
gvc.Header = myColumns[c.ColumnName.ToLower()].Column_show;
FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
text.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
if (table.Columns[i].ColumnName.ToLower().Contains("date"))
{
text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
}
else
{
text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
}
DataTemplate dataTemplate = new DataTemplate() { VisualTree = text };
gvc.CellTemplate = dataTemplate;
gvc.Width = 12 * myColumns[c.ColumnName.ToLower()].Width;
_gridview.Columns.Add(gvc);
}
if (BShowModify)
{
GridViewColumn gvc_modify = new GridViewColumn();
gvc_modify.Header = "修改";
FrameworkElementFactory button_modify = new FrameworkElementFactory(typeof(Button));
button_modify.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
button_modify.SetValue(Button.WidthProperty, 20.0);
button_modify.AddHandler(Button.ClickEvent, new RoutedEventHandler(modify_Click));
button_modify.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
button_modify.SetResourceReference(Button.StyleProperty, "ListModifyImageButtonTemplate");
DataTemplate dataTemplate_modify = new DataTemplate() { VisualTree = button_modify };
gvc_modify.CellTemplate = dataTemplate_modify;
_gridview.Columns.Add(gvc_modify);
}
if (BShowDelete)
{
GridViewColumn gvc_delete = new GridViewColumn();
gvc_delete.Header = "删除";
FrameworkElementFactory button_delete = new FrameworkElementFactory(typeof(Button));
button_delete.SetValue(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
button_delete.SetValue(Button.WidthProperty, 20.0);
button_delete.AddHandler(Button.ClickEvent, new RoutedEventHandler(delete_Click));
button_delete.SetResourceReference(Button.StyleProperty, "ListDeleteImageButtonTemplate");
button_delete.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
DataTemplate dataTemplate_delete = new DataTemplate() { VisualTree = button_delete };
gvc_delete.CellTemplate = dataTemplate_delete;
_gridview.Columns.Add(gvc_delete);
}
if (BShowDetails)
{
GridViewColumn gvc_details = new GridViewColumn();
gvc_details.Header = "详情";
FrameworkElementFactory button_details = new FrameworkElementFactory(typeof(Button));
button_details.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
button_details.SetValue(Button.WidthProperty, 20.0);
button_details.AddHandler(Button.ClickEvent, new RoutedEventHandler(details_Click));
button_details.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
button_details.SetResourceReference(Button.StyleProperty, "ListModifyImageButtonTemplate");
DataTemplate dataTemplate_details = new DataTemplate() { VisualTree = button_details };
gvc_details.CellTemplate = dataTemplate_details;
_gridview.Columns.Add(gvc_details);
}
if (BShowState)
{
GridViewColumn gvc_state = new GridViewColumn();
gvc_state.Header = "状态";
//.........这里部分代码省略.........
示例3: SetDataTable
//private List<int> sumColumns = new List<int>();
public void SetDataTable(DataTable _dt, string title, List<int> columnNumbers)
{
this.dt = _dt.Copy();
this.title = title;
this.columnNumbers = columnNumbers;
_title.Text = "▪ " + title;
_gridview.Columns.Clear();
foreach (DataColumn c in dt.Columns)
{
GridViewColumn gvc = new GridViewColumn();
gvc.Header = c.ColumnName;
gvc.Width = (_listview.ActualWidth - 40) / dt.Columns.Count - 44;
//gvc.DisplayMemberBinding = (new Binding(c.ColumnName));
FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
text.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
DataTemplate dataTemplate = new DataTemplate() { VisualTree = text };
gvc.CellTemplate = dataTemplate;
gvc.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);
_gridview.Columns.Add(gvc);
}
if (BShowDetails)
{
GridViewColumn gvc_details = new GridViewColumn();
gvc_details.Header = "详情";
FrameworkElementFactory button_details = new FrameworkElementFactory(typeof(Button));
button_details.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
button_details.SetValue(Button.WidthProperty, 40.0);
button_details.AddHandler(Button.ClickEvent, new RoutedEventHandler(details_Click));
button_details.SetBinding(Button.TagProperty, new Binding(dt.Columns[1].ColumnName));
button_details.SetValue(Button.ContentProperty, ">>");
button_details.SetValue(Button.ForegroundProperty, Brushes.Blue);
button_details.SetValue(Button.FontSizeProperty, 14.0);
button_details.SetBinding(Button.VisibilityProperty, new Binding(dt.Columns[0].ColumnName) { Converter = new VisibleBtnConverter() });
DataTemplate dataTemplate_details = new DataTemplate() { VisualTree = button_details };
gvc_details.CellTemplate = dataTemplate_details;
_gridview.Columns.Add(gvc_details);
}
_listview.ItemsSource = dt.DefaultView;
}
示例4: CreateDefaultControlTemplate
// Creates the default control template for ScrollViewer.
private static ControlTemplate CreateDefaultControlTemplate()
{
ControlTemplate template = null;
// Our default style is a 2x2 grid:
// <Grid Columns="*,Auto" Rows="*,Auto"> // Grid
// <ColumnDefinition Width="*" />
// <ColumnDefinition Width="Auto" />
// <RowDefinition Height="*" />
// <RowDefinition Height="Auto" />
// <Border> // Cell 1-2, 1-2
// <ScrollContentPresenter />
// </Border>
// <VerticalScrollBar /> // Cell 1, 2
// <HorizontalScrollBar /> // Cell 2, 1
// </Grid>
FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid), "Grid");
FrameworkElementFactory gridColumn1 = new FrameworkElementFactory(typeof(ColumnDefinition), "ColumnDefinitionOne");
FrameworkElementFactory gridColumn2 = new FrameworkElementFactory(typeof(ColumnDefinition), "ColumnDefinitionTwo");
FrameworkElementFactory gridRow1 = new FrameworkElementFactory(typeof(RowDefinition), "RowDefinitionOne");
FrameworkElementFactory gridRow2 = new FrameworkElementFactory(typeof(RowDefinition), "RowDefinitionTwo");
FrameworkElementFactory vsb = new FrameworkElementFactory(typeof(ScrollBar), VerticalScrollBarTemplateName);
FrameworkElementFactory hsb = new FrameworkElementFactory(typeof(ScrollBar), HorizontalScrollBarTemplateName);
FrameworkElementFactory content = new FrameworkElementFactory(typeof(ScrollContentPresenter), ScrollContentPresenterTemplateName);
FrameworkElementFactory corner = new FrameworkElementFactory(typeof(Rectangle), "Corner");
// Bind Actual HorizontalOffset to HorizontalScrollBar.Value
// Bind Actual VerticalOffset to VerticalScrollbar.Value
Binding bindingHorizontalOffset = new Binding("HorizontalOffset");
bindingHorizontalOffset.Mode = BindingMode.OneWay;
bindingHorizontalOffset.RelativeSource = RelativeSource.TemplatedParent;
Binding bindingVerticalOffset = new Binding("VerticalOffset");
bindingVerticalOffset.Mode = BindingMode.OneWay;
bindingVerticalOffset.RelativeSource = RelativeSource.TemplatedParent;
grid.SetValue(Grid.BackgroundProperty, new TemplateBindingExtension(BackgroundProperty));
grid.AppendChild(gridColumn1);
grid.AppendChild(gridColumn2);
grid.AppendChild(gridRow1);
grid.AppendChild(gridRow2);
grid.AppendChild(corner);
grid.AppendChild(content);
grid.AppendChild(vsb);
grid.AppendChild(hsb);
gridColumn1.SetValue(ColumnDefinition.WidthProperty, new GridLength(1.0, GridUnitType.Star));
gridColumn2.SetValue(ColumnDefinition.WidthProperty, new GridLength(1.0, GridUnitType.Auto));
gridRow1.SetValue(RowDefinition.HeightProperty, new GridLength(1.0, GridUnitType.Star));
gridRow2.SetValue(RowDefinition.HeightProperty, new GridLength(1.0, GridUnitType.Auto));
content.SetValue(Grid.ColumnProperty, 0);
content.SetValue(Grid.RowProperty, 0);
content.SetValue(ContentPresenter.MarginProperty, new TemplateBindingExtension(PaddingProperty));
content.SetValue(ContentProperty, new TemplateBindingExtension(ContentProperty));
content.SetValue(ContentTemplateProperty, new TemplateBindingExtension(ContentTemplateProperty));
content.SetValue(CanContentScrollProperty, new TemplateBindingExtension(CanContentScrollProperty));
hsb.SetValue(ScrollBar.OrientationProperty, Orientation.Horizontal);
hsb.SetValue(Grid.ColumnProperty, 0);
hsb.SetValue(Grid.RowProperty, 1);
hsb.SetValue(RangeBase.MinimumProperty, 0.0);
hsb.SetValue(RangeBase.MaximumProperty, new TemplateBindingExtension(ScrollableWidthProperty));
hsb.SetValue(ScrollBar.ViewportSizeProperty, new TemplateBindingExtension(ViewportWidthProperty));
hsb.SetBinding(RangeBase.ValueProperty, bindingHorizontalOffset);
hsb.SetValue(UIElement.VisibilityProperty, new TemplateBindingExtension(ComputedHorizontalScrollBarVisibilityProperty));
hsb.SetValue(FrameworkElement.CursorProperty, Cursors.Arrow);
hsb.SetValue(AutomationProperties.AutomationIdProperty, "HorizontalScrollBar");
vsb.SetValue(Grid.ColumnProperty, 1);
vsb.SetValue(Grid.RowProperty, 0);
vsb.SetValue(RangeBase.MinimumProperty, 0.0);
vsb.SetValue(RangeBase.MaximumProperty, new TemplateBindingExtension(ScrollableHeightProperty));
vsb.SetValue(ScrollBar.ViewportSizeProperty, new TemplateBindingExtension(ViewportHeightProperty));
vsb.SetBinding(RangeBase.ValueProperty, bindingVerticalOffset);
vsb.SetValue(UIElement.VisibilityProperty, new TemplateBindingExtension(ComputedVerticalScrollBarVisibilityProperty));
vsb.SetValue(FrameworkElement.CursorProperty, Cursors.Arrow);
vsb.SetValue(AutomationProperties.AutomationIdProperty, "VerticalScrollBar");
corner.SetValue(Grid.ColumnProperty, 1);
corner.SetValue(Grid.RowProperty, 1);
corner.SetResourceReference(Rectangle.FillProperty, SystemColors.ControlBrushKey);
template = new ControlTemplate(typeof(ScrollViewer));
template.VisualTree = grid;
template.Seal();
return (template);
}
示例5: update
private void update()
{
if (table == null )
{
return;
}
//int sumWidth = 0;
//for (int j = 0; j < table.Columns.Count; j++)
//{
// int maxWidth = System.Text.Encoding.Default.GetByteCount(table.Columns[j].ColumnName.ToString());
// for (int i = 0; i < table.Rows.Count; i++)
// {
// if (maxWidth < System.Text.Encoding.Default.GetByteCount(table.Rows[i][j].ToString().Trim()))
// {
// maxWidth = System.Text.Encoding.Default.GetByteCount(table.Rows[i][j].ToString().Trim());
// }
// }
// sumWidth += maxWidth;
// myColumns[table.Columns[j].ColumnName.ToLower()].Width = maxWidth;
//}
_gridview.Columns.Clear();
for (int i = 0; i < table.Columns.Count; i++)
{
DataColumn c = table.Columns[i];
if (!myColumns[c.ColumnName.ToLower()].BShow)
{
continue;
}
GridViewColumn gvc = new GridViewColumn();
gvc.Header = myColumns[c.ColumnName.ToLower()].Column_show;
FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
text.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
if (table.Columns[i].ColumnName.ToLower().Contains("date"))
{
text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
}
else
{
text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
}
//当列为任务完成率和任务总完成率时,显示为红色
if (myColumns[c.ColumnName.ToLower()].Column_show == "任务完成率" || myColumns[c.ColumnName.ToLower()].Column_show == "任务总完成率"
|| myColumns[c.ColumnName.ToLower()].Column_show == "抽检率" || myColumns[c.ColumnName.ToLower()].Column_show == "综合平均抽检率")
{
text.SetValue(TextBlock.ForegroundProperty, Brushes.Blue);
}
//当检测结果是疑似阳性或者阳性时,内容为红色
if (myColumns[c.ColumnName.ToLower()].Column_show == "疑似阳性样本" || myColumns[c.ColumnName.ToLower()].Column_show == "阳性样本")
{
text.SetValue(TextBlock.ForegroundProperty, Brushes.Red);
}
DataTemplate dataTemplate = new DataTemplate() { VisualTree = text };
gvc.CellTemplate = dataTemplate;
gvc.Width = 12 * myColumns[c.ColumnName.ToLower()].Width;
_gridview.Columns.Add(gvc);
}
if (BShowModify)
{
GridViewColumn gvc_modify = new GridViewColumn();
gvc_modify.Width = 60;
gvc_modify.Header = "设置";
FrameworkElementFactory button_modify = new FrameworkElementFactory(typeof(Button));
button_modify.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
button_modify.SetValue(Button.WidthProperty, 20.0);
button_modify.AddHandler(Button.ClickEvent, new RoutedEventHandler(modify_Click));
button_modify.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
button_modify.SetResourceReference(Button.StyleProperty, "ListSetImageButtonTemplate");
button_modify.SetBinding(Button.VisibilityProperty, new Binding(table.Columns[0].ColumnName) { Converter = new VisibleBtnConverter() });
DataTemplate dataTemplate_modify = new DataTemplate() { VisualTree = button_modify };
gvc_modify.CellTemplate = dataTemplate_modify;
_gridview.Columns.Add(gvc_modify);
}
if (BShowDelete)
{
GridViewColumn gvc_delete = new GridViewColumn();
gvc_delete.Header = "删除";
FrameworkElementFactory button_delete = new FrameworkElementFactory(typeof(Button));
button_delete.SetValue(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
button_delete.SetValue(Button.WidthProperty, 20.0);
button_delete.AddHandler(Button.ClickEvent, new RoutedEventHandler(delete_Click));
button_delete.SetResourceReference(Button.StyleProperty, "ListDeleteImageButtonTemplate");
button_delete.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
DataTemplate dataTemplate_delete = new DataTemplate() { VisualTree = button_delete };
gvc_delete.CellTemplate = dataTemplate_delete;
_gridview.Columns.Add(gvc_delete);
}
if (BShowDetails)
{
GridViewColumn gvc_details = new GridViewColumn();
gvc_details.Header = "详情";
//.........这里部分代码省略.........
示例6: update
private void update()
{
if (table == null)
{
return;
}
_gridview.Columns.Clear();
//int sumWidth = 0;
//for (int j = 0; j < table.Columns.Count; j++)
//{
// int maxWidth = System.Text.Encoding.Default.GetByteCount(table.Columns[j].ColumnName.ToString());
// for (int i = 0; i < table.Rows.Count; i++)
// {
// if (maxWidth < System.Text.Encoding.Default.GetByteCount(table.Rows[i][j].ToString().Trim()))
// {
// maxWidth = System.Text.Encoding.Default.GetByteCount(table.Rows[i][j].ToString().Trim());
// }
// }
// sumWidth += maxWidth;
// myColumns[table.Columns[j].ColumnName.ToLower()].Width = maxWidth;
//}
for (int i = 0; i < table.Columns.Count; i++)
{
DataColumn c = table.Columns[i];
if (myColumns[c.ColumnName.ToLower()].Column_show == "总行数")
{
if (table.Rows.Count != 0)
{
RowTotal = Convert.ToInt32(table.Rows[0][c.ColumnName].ToString());
PageTotal = (int)Math.Ceiling((double)RowTotal / (double)RowMax);
}
else
{
RowTotal = 0;
PageTotal = 0;
}
}
if (!myColumns[c.ColumnName.ToLower()].BShow)
{
continue;
}
GridViewColumn gvc = new GridViewColumn();
gvc.Header = myColumns[c.ColumnName.ToLower()].Column_show;
FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
text.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
text.SetBinding(TextBlock.ForegroundProperty, new Binding(c.ColumnName) { Converter = new RedFontConverter() });
if (table.Columns[i].ColumnName.ToLower().Contains("date"))
{
text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
}
else
{
text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
}
//当检测结果是疑似阳性或者阳性时,内容为红色
if (myColumns[c.ColumnName.ToLower()].Column_show == "疑似阳性" || myColumns[c.ColumnName.ToLower()].Column_show == "阳性")
{
text.SetValue(TextBlock.ForegroundProperty, Brushes.Red);
}
DataTemplate dataTemplate = new DataTemplate() { VisualTree = text };
gvc.CellTemplate = dataTemplate;
gvc.Width = 10 * myColumns[c.ColumnName.ToLower()].Width;
_gridview.Columns.Add(gvc);
}
if (BShowModify)
{
GridViewColumn gvc_modify = new GridViewColumn();
gvc_modify.Header = "修改";
FrameworkElementFactory button_modify = new FrameworkElementFactory(typeof(Button));
button_modify.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
button_modify.SetValue(Button.WidthProperty, 20.0);
button_modify.AddHandler(Button.ClickEvent, new RoutedEventHandler(modify_Click));
button_modify.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
button_modify.SetResourceReference(Button.StyleProperty, "ListModifyImageButtonTemplate");
DataTemplate dataTemplate_modify = new DataTemplate() { VisualTree = button_modify };
gvc_modify.CellTemplate = dataTemplate_modify;
_gridview.Columns.Add(gvc_modify);
}
if (BShowDelete)
{
GridViewColumn gvc_delete = new GridViewColumn();
gvc_delete.Header = "删除";
FrameworkElementFactory button_delete = new FrameworkElementFactory(typeof(Button));
button_delete.SetValue(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
button_delete.SetValue(Button.WidthProperty, 20.0);
button_delete.AddHandler(Button.ClickEvent, new RoutedEventHandler(delete_Click));
button_delete.SetResourceReference(Button.StyleProperty, "ListDeleteImageButtonTemplate");
button_delete.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
DataTemplate dataTemplate_delete = new DataTemplate() { VisualTree = button_delete };
gvc_delete.CellTemplate = dataTemplate_delete;
_gridview.Columns.Add(gvc_delete);
}
if (BShowDetails)
//.........这里部分代码省略.........
示例7: AddToggleButtonForDetailView
private void AddToggleButtonForDetailView()
{
DataGridTemplateColumn theColumn = new DataGridTemplateColumn();
theColumn.Header = "";
FrameworkElementFactory theFactory = new FrameworkElementFactory(typeof(ToggleButton));
#region Set Binding
//Binding b1 = new Binding("IsSingleTabFixed");
//b1.Mode = BindingMode.TwoWay;
//theFactory.SetValue(CheckBox.IsCheckedProperty, b1);
#endregion End Set Binding
//Set Style to dynamic source Resources/Style.xaml
theFactory.SetResourceReference(StyleProperty, "TwistyButtonStyle");
theFactory.AddHandler(CheckBox.ClickEvent, new RoutedEventHandler(ToggleButton_Click));
theColumn.CellTemplate = new DataTemplate()
{
VisualTree = theFactory
};
theColumn.DisplayIndex = 0;
this.Columns.Add(theColumn);
}