【问题标题】:Can't access ComboBox in DataGridTemplateColumn (C#)无法访问 DataGridTemplateColumn 中的 ComboBox (C#)
【发布时间】:2014-11-11 20:20:24
【问题描述】:

我在 xaml 中有以下代码:

                    <DataGridTemplateColumn Header="Status" Width="120">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <ComboBox x:Name="_status" ItemsSource="{Binding status}" />
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

谁能解释一下为什么我不能访问 _status ComboBox?我正在尝试将其分配给:

_status.ItemsSource = statuses.jobStatus();

【问题讨论】:

  • _status 只能在 CellTemplate 中访问,代码隐藏中的当前上下文超出了该范围。请在这里使用一些模式,使用 Binding 而不是像那样设置 ItemsSource。
  • 我怎样才能将它绑定到另一个类中的方法呢?没有太多的xaml经验

标签: c# wpf xaml combobox


【解决方案1】:

好的,那么问题是_statusName 属性不可见,因为它会与生成的DataTemplate 的前一个或下一个同级冲突。完整描述是here

【讨论】:

    【解决方案2】:

    我做了一些研究,发现了那篇文章。 可能对某人有用。易于使用!

    http://www.dev102.com/2008/08/07/how-to-access-a-wpf-control-which-is-located-in-a-datatemplate/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-13
      • 1970-01-01
      • 1970-01-01
      • 2014-04-14
      • 2013-06-30
      • 1970-01-01
      • 1970-01-01
      • 2012-02-01
      相关资源
      最近更新 更多