English 中文(简体)
获得数据信息
原标题:Get notified of DataContext changed in a WPF Resource

我对《世界森林框架》有约束力。 基本上,我宣布了我的用户框架资源,但当上级用户数据目录发生变化时,该项目似乎没有得到通知。

基本上,在我的用户中 我在项目一览表中有一个项目组合。 在这次征程中,我需要接受亲人观点的摩德尔的话,因此,我带着我所认为的trick笑。 我从收集《意见书》中抽取一 cu,就把我的亲人观点模式与资源挂钩,然后利用这一资源从数据模板中获取《观点》。

    <UserControl.Resources>
        <cont:ViewModelSource Source="{Binding}" x:Key="ParentViewModel"/>
    </UserControl.Resources>

因此,我可以这样说:

CommandParameter="{Binding ViewModel.OpenEntity, Source={StaticResource ParentViewModel}}"

所有这一切似乎都在工作,但除外,在用户目录重新编造时,《观点》的数据内容就没有变化。 现在,我 ha忙地做这项工作:在“用户数据汇编”的编码背后,确定资料库。

我看着收集意见书是如何做到的,但似乎没有做任何特殊的事情。

任何人都知道为什么发生这种情况,或者我如何确定这种情况?

问题回答

我有同样的问题,我找到了解决办法。

首先,我试图将我的观点纳入数据内容。 错误。

然后,我试图将我的观点Model确定为资源,并为资源确定我的根本要素的具有约束力的来源。 错误。

最后,我创建了一个四轮运输机,将模型(Witch is DataContext of the control)转换成一个观点模型。 然后,I Bind数据与变换者混淆了我的基本内容。

<UserControl.Resources>

    <local:PersonToControllerConverter x:Key="PersonToControllerConverter"/>

    <!--<local:PersonController x:Key="controller"
        Value="{Binding}"
        Parent="{Binding Path=DataContext,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}"
        />-->

</UserControl.Resources>



<Border x:Name="root" BorderBrush="Black" BorderThickness="2" >
    <Border.DataContext>
        <MultiBinding Converter="{StaticResource PersonToControllerConverter}">
            <Binding/>
            <Binding Path="DataContext" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}"/>
        </MultiBinding>
    </Border.DataContext>

    <!--DataContext="{Binding Source={StaticResource controller}}">-->

    <!--<Border.DataContext>
        <local:PersonController
                    Value="{Binding}"
                    Parent="{Binding Path=DataContext,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}"
                    />
    </Border.DataContext>-->

我认为,当数据内容在根本内容上发生变化时,如果内容不具有约束力,那么数据内容就停止了被打破的约束力。

或许,你必须创建一个中标,以实施<条码>指定所有人接口。





相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签