【问题标题】:How to gain access to the controls of other pages in a UserControl?如何访问 UserControl 中其他页面的控件?
【发布时间】:2015-09-27 13:20:39
【问题描述】:

我创建了一个 UserControl 我将一个 ListView 发布为 DataTemplate

<ListView.ItemTemplate>
  <DataTemplate>
     <local:Favorites/>
  </DataTemplate>
</ListView.ItemTemplate>

UserControl 我需要在 ListView 的页面上使用 TextBlock 的 Text 属性。我们如何访问该控件和其他控件?

例子:

if (query.Count == 0)
{
    NoPreferiti.Visibility = Visibility.Visible;  //NO ACCESS
}

【问题讨论】:

  • 你不能。尝试使用 Element 属性或将其作为收藏夹的属性传递。例如,如果收藏夹有“文本”,请将其

标签: c# xaml windows-phone-8.1


【解决方案1】:

唯一可行的方法是将“父”控件作为属性传递给 UserControl,通过代码或 xaml。

一种简单的方法是在父页面中向 UserControl 添加 Loaded 事件,并在事件处理程序中将要在 UserControl 内更改的控件分配为 UserControl 的参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-04
    • 1970-01-01
    • 2017-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-29
    相关资源
    最近更新 更多