相关疑难解决方法(0)

WPF数据绑定:如何访问"父"数据上下文?

我有一个窗口中包含的列表(见下文).窗口DataContext有两个属性,ItemsAllowItemCommand.

如何获取针对窗口的属性需要解析HyperlinkCommand属性DataContext

<ListView ItemsSource="{Binding Items}">
  <ListView.View>
    <GridView>
      <GridViewColumn Header="Action">
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <StackPanel>
              <TextBlock>

                <!-- this binding is not working -->
                <Hyperlink Command="{Binding AllowItemCommand}"
                           CommandParameter="{Binding .}">
                    <TextBlock Text="Allow" />
                </Hyperlink>

              </TextBlock>
            </StackPanel>
          </DataTemplate>
        </GridViewColumn.CellTemplate>
      </GridViewColumn>
    </GridView>
  </ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud)

data-binding wpf datacontext

202
推荐指数
3
解决办法
16万
查看次数

标签 统计

data-binding ×1

datacontext ×1

wpf ×1