【发布时间】:2014-06-13 19:33:34
【问题描述】:
我有自己的控制,绑定在其中不起作用。下面是我尝试绑定的代码。
XAML 中的代码
<cc:MyControl Name="myControl" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemSource="{Binding Path=Document}"></cc:MyControl>
ItemSource 依赖属性的 CodeBehind 中的代码
public Object ItemSource
{
get { return (Object)GetValue(ItemSourceProperty); }
set { SetValue(ItemSourceProperty, value); }
}
public static readonly DependencyProperty ItemSourceProperty =
DependencyProperty.Register("ItemSource", typeof(Object), typeof(MyControl), new PropertyMetadata(null, new PropertyChangedCallback(DocumentLoadCallBack)));
private static void DocumentLoadCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
这甚至没有被触发.....
但是当我为 ItemSource 提供一些数据而没有如下绑定时,会触发 DocumentLoadCallBack。
<cc:MyControl Name="myControl" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemSource="ImagePath"></cc:MyControl>
“文档”绑定属性代码
public sealed partial class MainPage : Page
{
private StorageFile _doc = null;
public StorageFile Document
{
get
{
if (this._doc == null)
{
this._doc = GetDoc().Result;
}
return this._doc;
}
set
{
this._doc = value;
}
}
private async Task<StorageFile> GetDoc()
{
//return imagedocument location
}
}
有人帮我解决这个问题吗?
【问题讨论】:
-
看起来是异步的?如果你调用
GetDoc,它不会马上返回结果?
标签: c# xaml binding windows-runtime winrt-xaml