English 中文(简体)
我如何写一个数据集,根据第二次扶养财产的变化改变扶养财产的价值?
原标题:How do I write a datatrigger to change the value of a dependency property based on a change of a second dependency property?

我想改变用户群中因第二次扶养财产(Type)变更而引发的扶养财产的状况。

我试图将数据提错定义如下,但出于某种原因,它做了大量工作:

<UserControl.Resources>
    <Style TargetType="{x:Type UserControls:MyUserControl}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding ViewType}" Value="ViewType2">
                <Setter Property="Mode" Value="Logon"/>
            </DataTrigger>
      </Style.Triggers>
    </Style>
</UserControl.Resources>

为了核实我的约束力正在正确运作,我写道,在同样的用户控制下测试了XAML:

    <Style x:Key="butstyle">
        <Style.Triggers>
            <DataTrigger Binding="{Binding ViewType}" Value="ViewType2">
                <Setter Property="Control.Foreground" Value="White"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

当我把这种风格划入一个纽州时,我看到在适当的时候将原色改成白色,这证明我对Gevpe的束缚正在发挥作用。

我似乎需要使用一种使用者控制下的风格。 资源(如上文法典的第一部分),但“男性”财产从未确定。

这是这样做的正确途径吗? 我试图尽可能在XAML中保持这一作用,但我感到不舒服的是,如果与视觉分子没有直接关系,那么触发因素如何发挥作用。

在相关情况下,“电离层”约束性财产在母用户范围内界定,“Mode”财产在MyUserControl上界定。

<>Update:

我利用变换者发现,我的触发点正在被称作,但我的集束手却因某种原因没有介入。 在这方面,我正试图制定我的《发展法》。 set门和OnModeChanged()被点击。 我的属地财产是否有任何错误?

    public enum ModeStates { Logon, NextState }

    public ModeStates Mode
    {
        get { return (ModeStates)GetValue(ModeProperty); }
        set { SetValue(ModeProperty, value); }
    }

    protected static readonly DependencyProperty ModeProperty = DependencyProperty.Register(
            "Mode", typeof(ModeStates), typeof(MyUserControl),
            new FrameworkPropertyMetadata(new PropertyChangedCallback(OnModeChanged))
            );


    private static void OnModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {

            // .......

    }

<>Update:

I was able to use DependencyPropertyDescriptor.AddValueChanged() to solve my problem in a pretty clean fashion.

最佳回答

如果所涉扶养财产由用户委员会确定,则需要将其划为风格,而不是在资源内添加一种缺省风格。

a. 在XAML中设置风格

<UserControl.Style>
    <Style TargetType="{x:Type UserControls:MyUserControl}">
      <!-- Triggers -- >
    </Style>
</UserControl.Style>
问题回答




相关问题
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 ...

热门标签