다양한 (RIA 서비스) 도메인 서비스의 일부 데이터를 집계하는보기 모델 클래스에서 해당 데이터를 가져 오는 Silverlight 페이지가 있습니다.DomainContext.Load를 사용하여 내 ViewModel의 속성을 채우는 방법은 무엇입니까?
이상적으로는 해당 컨트롤을 뷰 모델 개체의 속성에 데이터 바인딩 할 수 있지만 페이지가로드 될 때 DomainContext.Load
은 쿼리를 비동기 적으로 실행하기 때문에 데이터를 사용할 수 없기를 바랍니다. Load
의 비동기 자연 위젯을 의미하기 때문에이 방법은 근본적으로 잘못 생각합니다
public class WidgetPageModel
{
private WidgetDomainContext WidgetContext { get; set; }
public WidgetPageModel()
{
this.WidgetContext = new WidgetDomainContext();
WidgetContext.Load(WidgetContext.GetAllWidgetsQuery(), false);
}
public IEnumerable<Widget> RedWidgets
{
get
{
return this.WidgetContext.Widgets.Where(w => w.Colour == "Red");
}
}
}
:
<navigation:Page x:Class="Demo.UI.Pages.WidgetPage"
// the usual xmlns stuff here...
xmlns:local="clr-namespace:Demo.UI.Pages" mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DataContext="{d:DesignInstance Type=local:WidgetPageModel, IsDesignTimeCreatable=False}"
d:DesignWidth="640" d:DesignHeight="480"
Title="Widget Page">
<Canvas x:Name="LayoutRoot">
<ListBox ItemsSource="{Binding RedWidgets}" Width="150" Height="500" />
</Canvas>
</navigation:Page>
내 뷰 모델은 다음과 같습니다
내 실버 라이트 페이지에는 다음과 같은 XAML을 가지고 목록은 반드시 ListBox 데이터가 바인딩 될 때 채워지지 않습니다. (내 저장소의 중단 점은 컬렉션에 채워지는 코드가 실행 중임을 보여 주지만 페이지 렌더링 후에 만 표시됩니다.)
누군가 올바른 방법을 보여줄 수 있습니까?