【问题标题】:Get x:Name from DependencyObject defined in XAML in WPF从 WPF 中 XAML 中定义的 DependencyObject 获取 x:Name
【发布时间】:2023-03-20 08:13:01
【问题描述】:

我正在尝试获取 DataGridColumn 的 x:Name。 DataGridColumn 直接从 DependencyObject 派生,因此我无法将其转换为 FrameworkElement 并使用 Name 属性。

这是我在 XAML 中的代码:

<toolkit:DataGridCheckBoxColumn Header="Abgerechnet" x:Name="DataGridColumAbgerechnet" />

现在我想通过 x:Name 在 DataGrid 中找到此列。

我该怎么做?

【问题讨论】:

  • 你在哪里尝试使用它,在 xaml.cs 中它应该在你这样做时直接可用。DataGridColumAbgerechnet
  • 我有一个函数将 DataGrid 作为 DependencyObject,但不在 xaml.cs 文件中。

标签: c# .net wpf xaml .net-3.5


【解决方案1】:

var column = (DataGridColumn)gridInstanceName.FindName("ColumnName");

应该得到你的专栏。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-26
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    • 2023-01-24
    相关资源
    最近更新 更多